In this article, we will see Operator Precedence in Sql .
When a complex expression has multiple operators, operator precedence determines the sequence in which the operations are performed. The order of execution can significantly affect the resulting value.
+-------+----------------------------------------------------------------------------+
| Level | Operators |
+-------+----------------------------------------------------------------------------+
| 1 | ~ (Bitwise NOT) |
| 2 | * (Multiply), / (Division), % (Modulo) |
| 3 | + , - , & (Bitwise AND), ^ (Bitwise Exclusive OR), | (Bitwise OR) |
| 4 | =, >, <, >=, <=, <>, !=, !>, !< (Comparison operators) |
| 5 | NOT |
| 6 | AND |
| 7 | ALL, ANY, BETWEEN, IN, LIKE, OR, SOME |
| 8 | = (Assignment) |
+------+-----------------------------------------------------------------------------+
Operators have the precedence levels shown in the following table. An operator on higher levels is evaluated before an operator on a lower level.
+-------+----------------------------------------------------------------------------+
| Level | Operators |
+-------+----------------------------------------------------------------------------+
| 1 | ~ (Bitwise NOT) |
| 2 | * (Multiply), / (Division), % (Modulo) |
| 3 | + , - , & (Bitwise AND), ^ (Bitwise Exclusive OR), | (Bitwise OR) |
| 4 | =, >, <, >=, <=, <>, !=, !>, !< (Comparison operators) |
| 5 | NOT |
| 6 | AND |
| 7 | ALL, ANY, BETWEEN, IN, LIKE, OR, SOME |
| 8 | = (Assignment) |
+------+-----------------------------------------------------------------------------+
Let's see the program for this.