The following rules define expression syntax in MySQL. The grammar shown here is based on that given in the
`sql/sql_yacc.yy`

file of MySQL source distributions. See the notes after the
grammar for additional information about some of the terms. Operator precedence is given in Section
12.3.1, "Operator Precedence".

:`expr`

OR`expr`

|`expr`

||`expr`

|`expr`

XOR`expr`

|`expr`

AND`expr`

|`expr`

&&`expr`

| NOT`expr`

| !`expr`

|`expr`

IS [NOT] {TRUE | FALSE | UNKNOWN} |`boolean_primary`

`boolean_primary`

:`boolean_primary`

IS [NOT] NULL |`boolean_primary`

<=>`boolean_primary`

|`predicate`

`boolean_primary`

`comparison_operator`

|`predicate`

`boolean_primary`

{ALL | ANY} (`comparison_operator`

) |`subquery`

`predicate`

: = | >= | > | <= | < | <> | !=`comparison_operator`

:`predicate`

[NOT] IN (`bit_expr`

) |`subquery`

[NOT] IN (`bit_expr`

[,`expr`

] ...) |`expr`

[NOT] BETWEEN`bit_expr`

AND`bit_expr`

|`predicate`

SOUNDS LIKE`bit_expr`

|`bit_expr`

[NOT] LIKE`bit_expr`

[ESCAPE`simple_expr`

] |`simple_expr`

[NOT] REGEXP`bit_expr`

|`bit_expr`

`bit_expr`

:`bit_expr`

|`bit_expr`

|`bit_expr`

&`bit_expr`

|`bit_expr`

<<`bit_expr`

|`bit_expr`

>>`bit_expr`

|`bit_expr`

+`bit_expr`

|`bit_expr`

-`bit_expr`

|`bit_expr`

*`bit_expr`

|`bit_expr`

/`bit_expr`

|`bit_expr`

DIV`bit_expr`

|`bit_expr`

MOD`bit_expr`

|`bit_expr`

%`bit_expr`

|`bit_expr`

^`bit_expr`

|`bit_expr`

+`bit_expr`

|`interval_expr`

-`bit_expr`

|`interval_expr`

`simple_expr`

:`simple_expr`

|`literal`

|`identifier`

|`function_call`

COLLATE`simple_expr`

|`collation_name`

|`param_marker`

|`variable`

||`simple_expr`

| +`simple_expr`

| -`simple_expr`

| ~`simple_expr`

| !`simple_expr`

| BINARY`simple_expr`

| (`simple_expr`

[,`expr`

] ...) | ROW (`expr`

,`expr`

[,`expr`

] ...) | (`expr`

) | EXISTS (`subquery`

) | {`subquery`

`identifier`

} |`expr`

|`match_expr`

|`case_expr`

`interval_expr`

Notes:

For literal value syntax, see Section 9.1, "Literal Values".

For identifier syntax, see Section 9.2, "Schema Object Names".

Variables can be user variables, system variables, or stored program local variables or parameters:

User variables: Section 9.4, "User-Defined Variables"

System variables: Section 5.1.5, "Using System Variables"

Local variables: Section 13.6.4.1, "Local Variable

`DECLARE`

Syntax"Parameters: Section 13.1.12, "

`CREATE PROCEDURE`

and`CREATE FUNCTION`

Syntax"

* param_marker* is

`'?'`

as used in prepared
statements for placeholders. See Section
13.5.1, "`PREPARE`

Syntax". `(`

indicates a subquery that
returns a single value; that is, a scalar subquery. See Section
13.2.10.1, "The Subquery as Scalar Operand". * subquery*)

`{`

is ODBC escape syntax and is accepted for ODBC
compatibility. The value is `identifier`

* expr*}

`expr`

* match_expr* indicates a

`MATCH`

expression. See Section 12.9,
"Full-Text Search Functions". * case_expr* indicates a

`CASE`

expression. See Section 12.4,
"Control Flow Functions". * interval_expr* represents a time interval. The syntax is

`INTERVAL ``expr`

`unit`

, where `unit`

`HOUR`

, `DAY`

, or `WEEK`

.
For the full list of `unit`

`DATE_ADD()`

function in Section
12.7, "Date and Time Functions". The meaning of some operators depends on the SQL mode:

By default,

`||`

is a logical`OR`

operator. With`PIPES_AS_CONCAT`

enabled,`||`

is string concatenation, with a precedence between`^`

and the unary operators.By default,

`!`

has a higher precedence than`NOT`

. With`HIGH_NOT_PRECEDENCE`

enabled,`!`

and`NOT`

have the same precedence.

Spec-Zone.ru - all specs in one place