<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="operator-precedence">
      </a>
      14.4.1 Operator Precedence
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045207581056">
  </a>
  <a class="indexterm" name="idm46045207579568">
  </a>
  <p>
   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.
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa87358476"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">INTERVAL</span>
<span class="token datatype">BINARY</span><span class="token punctuation">,</span> <span class="token keyword">COLLATE</span>
<span class="token operator">!</span>
<span class="token operator">-</span> <span class="token punctuation">(</span>unary minus<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">~</span> <span class="token punctuation">(</span>unary <span class="token datatype">bit</span> inversion<span class="token punctuation">)</span>
<span class="token operator">^</span>
<span class="token operator">*</span><span class="token punctuation">,</span> <span class="token operator">/</span><span class="token punctuation">,</span> <span class="token operator">DIV</span><span class="token punctuation">,</span> <span class="token operator">%</span><span class="token punctuation">,</span> <span class="token operator">MOD</span>
<span class="token operator">-</span><span class="token punctuation">,</span> <span class="token operator">+</span>
<span class="token operator">&lt;&lt;</span><span class="token punctuation">,</span> <span class="token operator">&gt;&gt;</span>
<span class="token operator">&amp;</span>
<span class="token operator">|</span>
<span class="token operator">=</span> <span class="token punctuation">(</span>comparison<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">&lt;=&gt;</span><span class="token punctuation">,</span> <span class="token operator">&gt;=</span><span class="token punctuation">,</span> <span class="token operator">&gt;</span><span class="token punctuation">,</span> <span class="token operator">&lt;=</span><span class="token punctuation">,</span> <span class="token operator">&lt;</span><span class="token punctuation">,</span> <span class="token operator">&lt;&gt;</span><span class="token punctuation">,</span> <span class="token operator">!=</span><span class="token punctuation">,</span> <span class="token operator">IS</span><span class="token punctuation">,</span> <span class="token operator">LIKE</span><span class="token punctuation">,</span> <span class="token operator">REGEXP</span><span class="token punctuation">,</span> <span class="token keyword">IN</span><span class="token punctuation">,</span> MEMBER <span class="token keyword">OF</span>
<span class="token operator">BETWEEN</span><span class="token punctuation">,</span> <span class="token operator">CASE</span><span class="token punctuation">,</span> <span class="token keyword">WHEN</span><span class="token punctuation">,</span> <span class="token keyword">THEN</span><span class="token punctuation">,</span> <span class="token keyword">ELSE</span>
<span class="token operator">NOT</span>
<span class="token operator">AND</span><span class="token punctuation">,</span> <span class="token operator">&amp;&amp;</span>
<span class="token keyword">XOR</span>
<span class="token operator">OR</span><span class="token punctuation">,</span> <span class="token operator">||</span>
<span class="token operator">=</span> <span class="token punctuation">(</span>assignment<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">:=</span></code></pre>
  </div>
  <p>
   The precedence of
   <code class="literal">
    =
   </code>
   depends on whether it is
        used as a comparison operator
        (
   <a class="link" href="comparison-operators.html#operator_equal">
    <code class="literal">
     =
    </code>
   </a>
   ) or as an
        assignment operator
        (
   <a class="link" href="assignment-operators.html#operator_assign-equal">
    <code class="literal">
     =
    </code>
   </a>
   ). When
        used as a comparison operator, it has the same precedence as
   <a class="link" href="comparison-operators.html#operator_equal-to">
    <code class="literal">
     &lt;=&gt;
    </code>
   </a>
   ,
   <a class="link" href="comparison-operators.html#operator_greater-than-or-equal">
    <code class="literal">
     &gt;=
    </code>
   </a>
   ,
   <a class="link" href="comparison-operators.html#operator_greater-than">
    <code class="literal">
     &gt;
    </code>
   </a>
   ,
   <a class="link" href="comparison-operators.html#operator_less-than-or-equal">
    <code class="literal">
     &lt;=
    </code>
   </a>
   ,
   <a class="link" href="comparison-operators.html#operator_less-than">
    <code class="literal">
     &lt;
    </code>
   </a>
   ,
   <a class="link" href="comparison-operators.html#operator_not-equal">
    <code class="literal">
     &lt;&gt;
    </code>
   </a>
   ,
   <a class="link" href="comparison-operators.html#operator_not-equal">
    <code class="literal">
     !=
    </code>
   </a>
   ,
   <a class="link" href="comparison-operators.html#operator_is">
    <code class="literal">
     IS
    </code>
   </a>
   ,
   <a class="link" href="string-comparison-functions.html#operator_like">
    <code class="literal">
     LIKE
    </code>
   </a>
   ,
   <a class="link" href="regexp.html#operator_regexp">
    <code class="literal">
     REGEXP
    </code>
   </a>
   , and
   <a class="link" href="comparison-operators.html#operator_in">
    <code class="literal">
     IN()
    </code>
   </a>
   . When used as an assignment
        operator, it has the same precedence as
   <a class="link" href="assignment-operators.html#operator_assign-value">
    <code class="literal">
     :=
    </code>
   </a>
   .
   <a class="xref" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
    Section 15.7.6.1, “SET Syntax for Variable Assignment”
   </a>
   , and
   <a class="xref" href="user-variables.html" title="11.4 User-Defined Variables">
    Section 11.4, “User-Defined Variables”
   </a>
   , explain how MySQL determines
        which interpretation of
   <code class="literal">
    =
   </code>
   should apply.
  </p>
  <p>
   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.
  </p>
  <p>
   The precedence and meaning of some operators depends on the SQL
        mode:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      By default,
      <a class="link" href="logical-operators.html#operator_or">
       <code class="literal">
        ||
       </code>
      </a>
      is a logical
      <a class="link" href="logical-operators.html#operator_or">
       <code class="literal">
        OR
       </code>
      </a>
      operator. With
      <a class="link" href="sql-mode.html#sqlmode_pipes_as_concat">
       <code class="literal">
        PIPES_AS_CONCAT
       </code>
      </a>
      enabled,
      <a class="link" href="logical-operators.html#operator_or">
       <code class="literal">
        ||
       </code>
      </a>
      is string
            concatenation, with a precedence between
      <a class="link" href="bit-functions.html#operator_bitwise-xor">
       <code class="literal">
        ^
       </code>
      </a>
      and
            the unary operators.
     </p>
    </li>
    <li class="listitem">
     <p>
      By default,
      <a class="link" href="logical-operators.html#operator_not">
       <code class="literal">
        !
       </code>
      </a>
      has a higher precedence than
      <code class="literal">
       NOT
      </code>
      . With
      <a class="link" href="sql-mode.html#sqlmode_high_not_precedence">
       <code class="literal">
        HIGH_NOT_PRECEDENCE
       </code>
      </a>
      enabled,
      <a class="link" href="logical-operators.html#operator_not">
       <code class="literal">
        !
       </code>
      </a>
      and
      <code class="literal">
       NOT
      </code>
      have the same precedence.
     </p>
    </li>
   </ul>
  </div>
  <p>
   See
   <a class="xref" href="sql-mode.html" title="7.1.11 Server SQL Modes">
    Section 7.1.11, “Server SQL Modes”
   </a>
   .
  </p>
  <a class="indexterm" name="idm46045207539168">
  </a>
  <a class="indexterm" name="idm46045207538096">
  </a>
  <a class="indexterm" name="idm46045207537024">
  </a>
  <a class="indexterm" name="idm46045207535536">
  </a>
  <p>
   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:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa11170717"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token number">1</span><span class="token operator">+</span><span class="token number">2</span><span class="token operator">*</span><span class="token number">3</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">7</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">+</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">3</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">9</span></code></pre>
  </div>
 </div>
 <br/>
</div>
