Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.4 Reference Manual  / ...  / Functions and Operators  / Operators  /  Operator Precedence

14.4.1 Operator Precedence

Operator precedences are shown in the following list, from highest precedence to the lowest. Operators that are shown together on a line have the same precedence.

INTERVALBINARY, COLLATE!- (unary minus), ~ (unary bit inversion)^*, /, DIV, %, MOD-, +<<, >>&|= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN, MEMBER OFBETWEEN, CASE, WHEN, THEN, ELSENOTAND, &&XOROR, ||= (assignment), :=

The precedence of= depends on whether it is used as a comparison operator (=) or as an assignment operator (=). When used as a comparison operator, it has the same precedence as<=>,>=,>,<=,<,<>,!=,IS,LIKE,REGEXP, andIN(). When used as an assignment operator, it has the same precedence as:=.Section 15.7.6.1, “SET Syntax for Variable Assignment”, andSection 11.4, “User-Defined Variables”, explain how MySQL determines which interpretation of= should apply.

For operators that occur at the same precedence level within an expression, evaluation proceeds left to right, with the exception that assignments evaluate right to left.

The precedence and meaning of some operators depends on the SQL mode:

  • By default,|| is a logicalOR operator. WithPIPES_AS_CONCAT enabled,|| is string concatenation, with a precedence between^ and the unary operators.

  • By default,! has a higher precedence thanNOT. WithHIGH_NOT_PRECEDENCE enabled,! andNOT have the same precedence.

SeeSection 7.1.11, “Server SQL Modes”.

The precedence of operators determines the order of evaluation of terms in an expression. To override this order and group terms explicitly, use parentheses. For example:

mysql> SELECT 1+2*3;        -> 7mysql> SELECT (1+2)*3;        -> 9