SQLite Operators

SQLite operators are reserved words or characters used in SQLite statements when we use WHERE clause to perform operations like comparisons and arithmetic operations.

Operators can be used to specify conditions and as conjunction for multiple conditions in SQLite statements.

There are mainly 4 type of operators in SQLite:

  • Arithmetic operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

SQLite Arithmetic Operators

The following table specifies the different arithmetic operators in SQLite. In this table, we have two variables “a” and “b” holding values 50 and 100 respectively.

OperatorDescriptionExample
+Addition Operator: It is used to add the values of both side of the operator.a+b = 150
Subtraction Operator: It is used to subtract the right hand operand from left hand operand.a-b = -50
*Multiplication Operator: It is used to multiply the values of both sides.a*b = 5000
/Division Operator: It is used to divide left hand operand by right hand operand.a/b = 0.5
%Modulus Operator: It is used to divide left hand operand by right hand operand and returns remainder.b/a = 0

SQLite Comparison Operator

The following table specifies the different comparison operators in SQLite. In this table, we have two variables “a” and “b” holding values 50 and 100 respectively.

OperatorDescriptionExample
==It is used to check if the values of two operands are equal or not, if yes then condition becomes true.(a == b) is not true.
=It is used to check if the values of two operands are equal or not, if yes then condition becomes true.(a = b) is not true.
!=It is used to check if the values of two operands are equal or not, if values are not equal then condition becomes true.(a != b) is true.
<>It is used to check if the values of two operands are equal or not, if values are not equal then condition becomes true.(a <> b) is true.
>It is used to check if the values of left operand is greater than the value of right operand, if yes then condition becomes true.(a > b) is not true.
<It is used to check if the values of left operand is less than the value of right operand, if yes then condition becomes true.(a < b) is true.
>=It is used to check if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.(a >= b) is not true.
<=It is used to check if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.(a <= b) is true.
!<It is used to check if the value of left operand is not less than the value of right operand, if yes then condition becomes true.(a !< b) is false.
!>It is used to check if the value of left operand is not greater than the value of right operand, if yes then condition becomes true.(a !> b) is true.

SQLite Logical Operator

Following is a list of logical operators in SQLite:

OperatorDescription
ANDThe AND operator allows the existence of multiple conditions in an SQL statement’s WHERE clause.
BETWEENThe BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value.
EXISTSThe EXISTS operator is used to search for the presence of a row in a specified table that meets certain criteria.
INThe IN operator is used to compare a value to a list of literal values that have been specified.
NOT INIt is the negation of IN operator which is used to compare a value to a list of literal values that have been specified.
LIKEThe LIKE operator is used to compare a value to similar values using wildcard operators.
GLOBThe GLOB operator is used to compare a value to similar values using wildcard operators. Also, glob is case sensitive, unlike like.
NOTThe NOT operator reverses the meaning of the logical operator with which it is used. For example: EXISTS, NOT BETWEEN, NOT IN, etc. These are known as negate operator.
ORThe OR operator is used to combine multiple conditions in an SQL statement’s where clause.
IS NULLThe NULL operator is used to compare a value with a null value.
ISThe IS operator work like =
IS NOTThe IS NOT operator work like !=
||This operator is used to add two different strings and make new one.
UNIQUEThe UNIQUE operator searches every row of a specified table for uniqueness (no duplicates).

AD

https://delivery.adrecover.com/recover.html?siteId=37784&dataDogLoggingEnabled=false&dataDogLoggingVersion=1

SQLite Bitwise Operators

SQLite Bitwise operators work on bits and perform bit by bit operation.

See the truth table for Binary AND (&) and Binary OR (|):

pqp&qp|q
0000
0101
1111
1001

Let’s assume two variables “a” and “b”, having values 60 and 13 respectively. So Binary values of a and b are:

a= 0011 1100

b= 0000 1101

a&b = 0000 1100

a|b = 0011 1101

~a = 1100 0011


OperatorDescriptionExample
&Binary AND operator copies a bit to the result if it exists in both operands.(a & b) will give 12 which is 0000 1100
|Binary OR Operator copies a bit if it exists in either operand.(a | b) will give 61 which is 0011 1101
~Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits.(~a ) will give -61 which is 1100 0011 in 2’s complement form due to a signed binary number.
<<Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.a << 2 will give 240 which is 1111 0000
>>Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.a >> 2 will give 15 which is 0000 1111

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *