# Operator Precedence

The precedence is the order in which the SQL operators are evaluated.

The following list shows the SQL operator precedence. **Operators that appear first in the list have a higher precedence.** Operators which are listed together have the same precedence.

* [INTERVAL](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/interval)
* [BINARY](https://mariadb.com/docs/server/reference/data-types/string-data-types/binary), [COLLATE](https://mariadb.com/docs/server/data-types/string-data-types/character-sets/setting-character-sets-and-collations#literals)
* [!](https://mariadb.com/docs/server/reference/sql-structure/operators/logical-operators/not)
* [-](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/set-operations/minus) (unary minus), [bitwise not](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/bit-functions-and-operators/bitwise-not) (unary bit inversion)
* `||` (string concatenation)
* [^](https://mariadb.com/docs/server/reference/sql-functions/aggregate-functions/bit_xor) (bitwise XOR)
* [\*](https://mariadb.com/docs/server/reference/sql-structure/operators/arithmetic-operators/multiplication-operator), [/](https://mariadb.com/docs/server/reference/sql-structure/operators/arithmetic-operators/division-operator), [DIV](https://mariadb.com/docs/server/reference/sql-functions/numeric-functions/div), [%](https://mariadb.com/docs/server/reference/sql-structure/operators/arithmetic-operators/modulo-operator), [MOD](https://mariadb.com/docs/server/reference/sql-functions/numeric-functions/mod) (multiplication, division, modulo)
* [-](https://mariadb.com/docs/server/reference/sql-structure/operators/arithmetic-operators/subtraction-operator), [+](https://mariadb.com/docs/server/reference/sql-structure/operators/arithmetic-operators/addition-operator) (subtraction, addition)
* [<<](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/bit-functions-and-operators/shift-left), [>>](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/bit-functions-and-operators/shift-right)
* [&](https://mariadb.com/docs/server/reference/sql-functions/aggregate-functions/bit_and) (bitwise AND)
* [|](https://mariadb.com/docs/server/reference/sql-functions/aggregate-functions/bit_or) (bitwise OR)
* [LIKE](https://mariadb.com/docs/server/reference/sql-functions/string-functions/like), [REGEXP](https://mariadb.com/docs/server/reference/sql-functions/string-functions/regular-expressions-functions/regexp), [IN](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/in)
* [BETWEEN](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/between-and)
* [=](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/equal) (comparison), [<=>](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/null-safe-equal), [>=](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/greater-than-or-equal), [>](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/greater-than), [<=](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/less-than-or-equal), [<](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/less-than), [<>](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/not-equal), [!=](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/not-equal), [IS](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/is)
* [NOT](https://mariadb.com/docs/server/reference/sql-structure/operators/logical-operators/not)
* [&&](https://mariadb.com/docs/server/reference/sql-structure/operators/logical-operators/and), [AND](https://mariadb.com/docs/server/reference/sql-structure/operators/logical-operators/and)
* [XOR](https://mariadb.com/docs/server/reference/sql-structure/operators/logical-operators/xor)
* [||](https://mariadb.com/docs/server/reference/sql-structure/operators/logical-operators/or) (logical or), [OR](https://mariadb.com/docs/server/reference/sql-structure/operators/logical-operators/or)
* [=](https://mariadb.com/docs/server/reference/sql-structure/operators/assignment-operators/assignment-operators-assignment-operator) (assignment), [:=](https://mariadb.com/docs/server/reference/sql-structure/operators/assignment-operators/assignment-operator)

{% hint style="warning" %}
Functions precedence is always higher than operators precedence.
{% endhint %}

If the `HIGH_NOT_PRECEDENCE` [SQL\_MODE](https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode) is set, `NOT` has the same precedence as `!`.

The `||` operator's precedence, as well as its meaning, depends on the `PIPES_AS_CONCAT` [SQL\_MODE](https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode) flag: if it is on, `||` can be used to concatenate strings (like the [CONCAT()](https://mariadb.com/docs/server/reference/sql-functions/string-functions/concat) function) and has a higher precedence.

The `=` operator's precedence depends on the context - it is higher when `=` is used as a comparison operator.

[Parentheses](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/bit-functions-and-operators/parentheses) can be used to modify the operators precedence in an expression.

## Short-Circuit Evaluation

The `AND`, `OR`, `&&` and `||` operators support short-circuit evaluation. This means that, in some cases, the expression on the right of those operators is not evaluated, because its result cannot affect the result. In the following cases, short-circuit evaluation is used and `x()` is not evaluated:

* `FALSE AND x()`
* `FALSE && x()`
* `TRUE OR x()`
* `TRUE || x()`
* `NULL BETWEEN x() AND x()`

Note however that the short-circuit evaluation does *not* apply to `NULL AND x()`. Also, `BETWEEN`'s right operands are not evaluated if the left operand is `NULL`, but in all other cases all the operands are evaluated.

This is a speed optimization. Also, since functions can have side-effects, this behavior can be used to choose whether execute them or not using a concise syntax:

```sql
SELECT some_function() OR log_error();
```

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-structure/operators/operator-precedence.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
