All Products
Search
Document Center

Operator priorities

Last Updated: Aug 18, 2020

The following table describes the precedence of operators in Distributed Relational Database Service (DRDS) goes from high to low.

Precedence Operator
15 !
14 -(Minus sign), ~
13 ^
12 *, /, %, MOD
11 +, -
10 <<,>>
9 &
8 |
7 =(comparison operator equals), <=>,>, >=, <, <=, <>, ! =, IS, LIKE, REGEXP, IN
6 BETWEEN
5 NOT
4 AND, &&
3 XOR
2 OR, ||
1 =(assignment operator)

Special notes

Precedence of IN, NOT IN, and =

Execute the following SQL statement in the MySQL 5.7.19:

  1. mysql> select binary 'a' = 'a' in (1, 2, 3);
  2. +-------------------------------+
  3. | binary 'a' = 'a' in (1, 2, 3) |
  4. +-------------------------------+
  5. | 1 |
  6. +-------------------------------+
  7. 1 row in set, 1 warning (0.01 sec)
  8. mysql> show warnings;
  9. +---------+------+---------------------------------------+
  10. | Level | Code | Message |
  11. +---------+------+---------------------------------------+
  12. | Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
  13. +---------+------+---------------------------------------+
  14. 1 row in set (0.00 sec)
  15. mysql> select 1 in (1, 2, 3) = 'a';
  16. +----------------------+
  17. | 1 in (1, 2, 3) = 'a' |
  18. +----------------------+
  19. | 0 |
  20. +----------------------+
  21. 1 row in set, 1 warning (0.00 sec)
  22. mysql> show warnings;
  23. +---------+------+---------------------------------------+
  24. | Level | Code | Message |
  25. +---------+------+---------------------------------------+
  26. | Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
  27. +---------+------+---------------------------------------+
  28. 1 row in set (0.00 sec)

In MySQL, the IN and NOT IN commands have a higher precedence than the = (comparison operator). In DRDS, the preceding precedence is strictly followed. In the case of the same precedence, use the left combination approach.