Operators are the built in reserve words which have specified meaning behind them. These operators are used with in query for some comparisons or other operations.
Operators In SQLite:
- Arithmetic
- Relational
- Logical
- Bitwise
ARITHMETIC
Arithmetic operators are used for basic mathematical operators i.e addition(+), subtraction(-), multiplication(*),division(/) and modulus(%).
Let’s consider A= 10 & B= 5.
- Addition : Add the values in either order it is defined, so A+B will give 15.
- Subtraction : Subtract the right side operand from left one, so A-B will give 5.
- Multiplication : Multiply the values in either order it is defined, so A*B will give 50.
- Division : Divide numerator by denominator, so A/B will give 2.
- Modulus : Divide the left side operand with right side and return remainder, so A%B will give 0.
RELATIONAL
Relational operators are also the basic mathematical operators.
Let’s consider A= 10 & B= 5.
- < : Return true when left operand is less than right , so (A<B) is false.
- <= : Return true when left operand is less than or equal to right , so (A<=B) is false.
- > : Return true when left operand is greater than right, so (A>B) is true.
- >= : Return true when left operand is greater than or equal to right, so (A>=B) is true.
- = or == : Return true when both operand are equal to each other, so (A=B) is false.
- != or <> : Return true when both operand are not equal to each other, so (A=B) is true.
LOGICAL
Here are the logical operators.
- AND : Return true when all conditions defined with AND are true, else false.
- OR= : Return true when any conditions defined with OR is true, else false
- NOT : It is negative operator, reverse the meaning of the operand.
- BETWEEN : The between operator returns the value defined between minimum & maximum value.
- IN : The IN operator allow to specify multiple values with it and return rows as specified.
- NOT IN : It is reverse of IN operator, returns values which or not specified, user can input multiple values in it.
- EXISTS : This operator finds weather specified row exists.
BITWISE
Here are the bitwise operators.
- & : Binary AND
- | : Binary OR
- >> : Binary right shift.
- << : Binary left shift.
Truth Table for ‘&’ and ‘|’
| A | B | A&B | A|B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |