Arithmetic operators
Operator |
Definition |
Example |
+ |
Addition |
SELECT 42 + 7; |
- |
Subtraction |
SELECT 42 - 7; |
* |
Multiplication |
SELECT 42 * 7; |
/ |
Division |
SELECT 42 / 7; |
% |
Modulus |
SELECT 42 % 7; |
Comparison operators
Operator |
Definition |
Example |
= |
Equal to |
SELECT * FROM Products
WHERE Price = 11; |
> |
Greater than |
SELECT * FROM Products
WHERE Price > 20; |
< |
Less than |
SELECT * FROM Products
WHERE Price < 20; |
>= |
Greater than or equal to |
SELECT * FROM Products
WHERE Price >= 20; |
<= |
Less than or equal to |
SELECT * FROM Products
WHERE Price <= 20; |
<> |
Not equal to |
SELECT * FROM Products
WHERE Price <> 20; |
Logical operators
Operator |
True if |
ALL |
All of the subquery values meet the condition |
AND |
All the conditions separated by AND are TRUE |
ANY |
Any of the subquery values meet the condition |
BETWEEN |
The operand is within the range of comparisons |
EXISTS |
The subquery returns one or more records |
IN |
The operand is equal to one of the listed expressions |
LIKE |
The operand matches a pattern |
NOT |
The condition(s) is NOT TRUE |
OR |
Any of the conditions separated by OR are TRUE |
SOME |
Any of the subquery values meet the condition |
Compound operators
Operator |
Definition |
+= |
Add assignment |
-= |
Subtract assignment |
*= |
Multiply assignment |
/= |
Divide assignment |
%= |
Modulus assignment |
Bitwise operators
Note: while bitwise SQL operators might seem similar to the logical SQL operators, they convert integers into binary bits and then perform the operations on each of them. The result is always an integer.
Operator |
Definition |
& |
Bitwise AND |
&= |
Bitwise AND EQUALS |
| |
Bitwise OR |
|= |
Bitwise OR EQUALS |
^ |
Bitwise exclusive OR |
^= |
Bitwise exclusive OR EQUALS |
~ |
Bitwise NOT |