<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="string-comparison-functions">
      </a>
      14.8.1 String Comparison Functions and Operators
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045202653600">
  </a>
  <a class="indexterm" name="idm46045202652560">
  </a>
  <a class="indexterm" name="idm46045202651072">
  </a>
  <a class="indexterm" name="idm46045202649984">
  </a>
  <div class="table">
   <a name="idm46045202648496">
   </a>
   <p class="title">
    <b>
     Table 14.13 String Comparison Functions and Operators
    </b>
   </p>
   <div class="table-contents">
    <table frame="box" rules="all" summary="A reference that lists string comparison functions and operators.">
     <colgroup>
      <col style="width: 28%"/>
      <col style="width: 71%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Name
       </th>
       <th>
        Description
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <a class="link" href="string-comparison-functions.html#operator_like">
         <code class="literal">
          LIKE
         </code>
        </a>
       </td>
       <td>
        Simple pattern matching
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="string-comparison-functions.html#operator_not-like">
         <code class="literal">
          NOT LIKE
         </code>
        </a>
       </td>
       <td>
        Negation of simple pattern matching
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="string-comparison-functions.html#function_strcmp">
         <code class="literal">
          STRCMP()
         </code>
        </a>
       </td>
       <td>
        Compare two strings
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <p>
   If a string function is given a binary string as an argument,
        the resulting string is also a binary string. A number converted
        to a string is treated as a binary string. This affects only
        comparisons.
  </p>
  <a class="indexterm" name="idm46045202632112">
  </a>
  <a class="indexterm" name="idm46045202630624">
  </a>
  <p>
   Normally, if any expression in a string comparison is
        case-sensitive, the comparison is performed in case-sensitive
        fashion.
  </p>
  <p>
   If a string function is invoked from within the
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   client, binary strings display using
        hexadecimal notation, depending on the value of the
   <a class="link" href="mysql-command-options.html#option_mysql_binary-as-hex">
    <code class="option">
     --binary-as-hex
    </code>
   </a>
   . For more
        information about that option, see
   <a class="xref" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    Section 6.5.1, “mysql — The MySQL Command-Line Client”
   </a>
   .
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <a name="operator_like">
     </a>
     <p>
      <a class="link" href="string-comparison-functions.html#operator_like">
       <code class="literal">
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        LIKE
        <em class="replaceable">
         <code>
          pat
         </code>
        </em>
        [ESCAPE
            '
        <em class="replaceable">
         <code>
          escape_char
         </code>
        </em>
        ']
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045202619360">
     </a>
     <p>
      Pattern matching using an SQL pattern. Returns
      <code class="literal">
       1
      </code>
      (
      <code class="literal">
       TRUE
      </code>
      ) or
      <code class="literal">
       0
      </code>
      (
      <code class="literal">
       FALSE
      </code>
      ). If either
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        pat
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      ,
            the result is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The pattern need not be a literal string. For example, it
            can be specified as a string expression or table column. In
            the latter case, the column must be defined as one of the
            MySQL string types (see
      <a class="xref" href="string-types.html" title="13.3 String Data Types">
       Section 13.3, “String Data Types”
      </a>
      ).
     </p>
     <p>
      Per the SQL standard,
      <a class="link" href="string-comparison-functions.html#operator_like">
       <code class="literal">
        LIKE
       </code>
      </a>
      performs matching on a per-character basis, thus it can
            produce results different from the
      <a class="link" href="comparison-operators.html#operator_equal">
       <code class="literal">
        =
       </code>
      </a>
      comparison
            operator:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74917833"><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 string">'ä'</span> <span class="token operator">LIKE</span> <span class="token string">'ae'</span> <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 'ä' LIKE 'ae' COLLATE latin1_german2_ci <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                                       0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'ä'</span> <span class="token operator">=</span> <span class="token string">'ae'</span> <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 'ä' = 'ae' COLLATE latin1_german2_ci <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                                    1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <a class="indexterm" name="idm46045202603312">
     </a>
     <p>
      In particular, trailing spaces are always significant. This
            differs from comparisons performed with the
      <a class="link" href="comparison-operators.html#operator_equal">
       <code class="literal">
        =
       </code>
      </a>
      operator,
            for which the significance of trailing spaces in nonbinary
            strings (
      <code class="literal">
       CHAR
      </code>
      ,
      <code class="literal">
       VARCHAR
      </code>
      , and
      <code class="literal">
       TEXT
      </code>
      values) depends on the pad attribute of the collation used
            for the comparison. For more information, see
      <a class="xref" href="charset-binary-collations.html#charset-binary-collations-trailing-space-comparisons" title="Trailing Space Handling in Comparisons">
       Trailing Space Handling in Comparisons
      </a>
      .
     </p>
     <p>
      With
      <a class="link" href="string-comparison-functions.html#operator_like">
       <code class="literal">
        LIKE
       </code>
      </a>
      you can use the
            following two wildcard characters in the pattern:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         <code class="literal">
          %
         </code>
         matches any number of characters,
                even zero characters.
        </p>
       </li>
       <li class="listitem">
        <p>
         <code class="literal">
          _
         </code>
         matches exactly one character.
        </p>
       </li>
      </ul>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa57380782"><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 string">'David!'</span> <span class="token operator">LIKE</span> <span class="token string">'David_'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'David!'</span> <span class="token operator">LIKE</span> <span class="token string">'%D%v%'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span></code></pre>
     </div>
     <p>
      To test for literal instances of a wildcard character,
            precede it by the escape character. If you do not specify
            the
      <code class="literal">
       ESCAPE
      </code>
      character,
      <code class="literal">
       \
      </code>
      is assumed, unless the
      <a class="link" href="sql-mode.html#sqlmode_no_backslash_escapes">
       <code class="literal">
        NO_BACKSLASH_ESCAPES
       </code>
      </a>
      SQL
            mode is enabled. In that case, no escape character is used.
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         <code class="literal">
          \%
         </code>
         matches one
         <code class="literal">
          %
         </code>
         character.
        </p>
       </li>
       <li class="listitem">
        <p>
         <code class="literal">
          \_
         </code>
         matches one
         <code class="literal">
          _
         </code>
         character.
        </p>
       </li>
      </ul>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96372949"><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 string">'David!'</span> <span class="token operator">LIKE</span> <span class="token string">'David\_'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'David_'</span> <span class="token operator">LIKE</span> <span class="token string">'David\_'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span></code></pre>
     </div>
     <p>
      To specify a different escape character, use the
      <code class="literal">
       ESCAPE
      </code>
      clause:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96648069"><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 string">'David_'</span> <span class="token operator">LIKE</span> <span class="token string">'David|_'</span> <span class="token keyword">ESCAPE</span> <span class="token string">'|'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span></code></pre>
     </div>
     <p>
      The escape sequence should be one character long to specify
            the escape character, or empty to specify that no escape
            character is used. The expression must evaluate as a
            constant at execution time. If the
      <a class="link" href="sql-mode.html#sqlmode_no_backslash_escapes">
       <code class="literal">
        NO_BACKSLASH_ESCAPES
       </code>
      </a>
      SQL
            mode is enabled, the sequence cannot be empty.
     </p>
     <p>
      The following statements illustrate that string comparisons
            are not case-sensitive unless one of the operands is
            case-sensitive (uses a case-sensitive collation or is a
            binary string):
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58413334"><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 string">'abc'</span> <span class="token operator">LIKE</span> <span class="token string">'ABC'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'abc'</span> <span class="token operator">LIKE</span> _utf8mb4 <span class="token string">'ABC'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_as_cs<span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'abc'</span> <span class="token operator">LIKE</span> _utf8mb4 <span class="token string">'ABC'</span> <span class="token keyword">COLLATE</span> utf8mb4_bin<span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'abc'</span> <span class="token operator">LIKE</span> <span class="token datatype">BINARY</span> <span class="token string">'ABC'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span></code></pre>
     </div>
     <p>
      As an extension to standard SQL, MySQL permits
      <a class="link" href="string-comparison-functions.html#operator_like">
       <code class="literal">
        LIKE
       </code>
      </a>
      on numeric expressions.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa54742789"><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">10</span> <span class="token operator">LIKE</span> <span class="token string">'1%'</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span></code></pre>
     </div>
     <p>
      MySQL attempts in such cases to perform implicit conversion
            of the expression to a string. See
      <a class="xref" href="type-conversion.html" title="14.3 Type Conversion in Expression Evaluation">
       Section 14.3, “Type Conversion in Expression Evaluation”
      </a>
      .
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       MySQL uses C escape syntax in strings (for example,
       <code class="literal">
        \n
       </code>
       to represent the newline character).
              If you want a
       <a class="link" href="string-comparison-functions.html#operator_like">
        <code class="literal">
         LIKE
        </code>
       </a>
       string to
              contain a literal
       <code class="literal">
        \
       </code>
       , you must double
              it. (Unless the
       <a class="link" href="sql-mode.html#sqlmode_no_backslash_escapes">
        <code class="literal">
         NO_BACKSLASH_ESCAPES
        </code>
       </a>
       SQL
              mode is enabled, in which case no escape character is
              used.) For example, to search for
       <code class="literal">
        \n
       </code>
       ,
              specify it as
       <code class="literal">
        \\n
       </code>
       . To search for
       <code class="literal">
        \
       </code>
       , specify it as
       <code class="literal">
        \\\\
       </code>
       ; this is because the backslashes
              are stripped once by the parser and again when the pattern
              match is made, leaving a single backslash to be matched
              against.
      </p>
      <p>
       Exception: At the end of the pattern string, backslash can
              be specified as
       <code class="literal">
        \\
       </code>
       . At the end of the
              string, backslash stands for itself because there is
              nothing following to escape. Suppose that a table contains
              the following values:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa28128819"><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> filename <span class="token keyword">FROM</span> t1<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> filename     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> C:           <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\          <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\Programs  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\Programs\ <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
      </div>
      <p>
       To test for values that end with backslash, you can match
              the values using either of the following patterns:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa57915763"><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> filename<span class="token punctuation">,</span> filename <span class="token operator">LIKE</span> <span class="token string">'%\\'</span> <span class="token keyword">FROM</span> t1<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> filename     <span class="token punctuation">|</span> filename LIKE '%\\' <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> C:           <span class="token punctuation">|</span>                   0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\          <span class="token punctuation">|</span>                   1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\Programs  <span class="token punctuation">|</span>                   0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\Programs\ <span class="token punctuation">|</span>                   1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> filename<span class="token punctuation">,</span> filename <span class="token operator">LIKE</span> <span class="token string">'%\\\\'</span> <span class="token keyword">FROM</span> t1<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> filename     <span class="token punctuation">|</span> filename LIKE '%\\\\' <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> C:           <span class="token punctuation">|</span>                     0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\          <span class="token punctuation">|</span>                     1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\Programs  <span class="token punctuation">|</span>                     0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> C:\Programs\ <span class="token punctuation">|</span>                     1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
      </div>
     </div>
    </li>
    <li class="listitem">
     <a name="operator_not-like">
     </a>
     <p>
      <a class="link" href="string-comparison-functions.html#operator_not-like">
       <code class="literal">
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        NOT LIKE
        <em class="replaceable">
         <code>
          pat
         </code>
        </em>
        [ESCAPE
            '
        <em class="replaceable">
         <code>
          escape_char
         </code>
        </em>
        ']
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045202543744">
     </a>
     <p>
      This is the same as
      <code class="literal">
       NOT
            (
       <em class="replaceable">
        <code>
         expr
        </code>
       </em>
       LIKE
       <em class="replaceable">
        <code>
         pat
        </code>
       </em>
       [ESCAPE
            '
       <em class="replaceable">
        <code>
         escape_char
        </code>
       </em>
       '])
      </code>
      .
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       Aggregate queries involving
       <a class="link" href="string-comparison-functions.html#operator_not-like">
        <code class="literal">
         NOT
              LIKE
        </code>
       </a>
       comparisons with columns containing
       <code class="literal">
        NULL
       </code>
       may yield unexpected results. For
              example, consider the following table and data:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43598887"><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">CREATE</span> <span class="token keyword">TABLE</span> foo <span class="token punctuation">(</span>bar <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> foo <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       The query
       <code class="literal">
        SELECT COUNT(*) FROM foo WHERE bar LIKE
              '%baz%';
       </code>
       returns
       <code class="literal">
        0
       </code>
       . You might
              assume that
       <code class="literal">
        SELECT COUNT(*) FROM foo WHERE bar
              NOT LIKE '%baz%';
       </code>
       would return
       <code class="literal">
        2
       </code>
       . However, this is not the case: The
              second query returns
       <code class="literal">
        0
       </code>
       . This is because
       <code class="literal">
        NULL NOT LIKE
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
       </code>
       always returns
       <code class="literal">
        NULL
       </code>
       , regardless of the value of
       <em class="replaceable">
        <code>
         expr
        </code>
       </em>
       . The same is true for
              aggregate queries involving
       <code class="literal">
        NULL
       </code>
       and
              comparisons using
       <a class="link" href="regexp.html#operator_not-regexp">
        <code class="literal">
         NOT
              RLIKE
        </code>
       </a>
       or
       <a class="link" href="regexp.html#operator_not-regexp">
        <code class="literal">
         NOT
              REGEXP
        </code>
       </a>
       . In such cases, you must test explicitly
              for
       <code class="literal">
        NOT NULL
       </code>
       using
       <a class="link" href="logical-operators.html#operator_or">
        <code class="literal">
         OR
        </code>
       </a>
       (and not
       <a class="link" href="logical-operators.html#operator_and">
        <code class="literal">
         AND
        </code>
       </a>
       ), as shown here:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa67149667"><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">SELECT</span> <span class="token function">COUNT</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token punctuation">)</span> <span class="token keyword">FROM</span> foo <span class="token keyword">WHERE</span> bar <span class="token operator">NOT</span> <span class="token operator">LIKE</span> <span class="token string">'%baz%'</span> <span class="token operator">OR</span> bar <span class="token operator">IS</span> <span class="token boolean">NULL</span><span class="token punctuation">;</span></code></pre>
      </div>
     </div>
    </li>
    <li class="listitem">
     <a name="function_strcmp">
     </a>
     <p>
      <a class="link" href="string-comparison-functions.html#function_strcmp">
       <code class="literal">
        STRCMP(
        <em class="replaceable">
         <code>
          expr1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          expr2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045202515664">
     </a>
     <p>
      <a class="link" href="string-comparison-functions.html#function_strcmp">
       <code class="literal">
        STRCMP()
       </code>
      </a>
      returns
      <code class="literal">
       0
      </code>
      if the strings are the same,
      <code class="literal">
       -1
      </code>
      if the first argument is smaller than
            the second according to the current sort order, and
      <code class="literal">
       NULL
      </code>
      if either argument is
      <code class="literal">
       NULL
      </code>
      . It returns
      <code class="literal">
       1
      </code>
      otherwise.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51253251"><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 function">STRCMP</span><span class="token punctuation">(</span><span class="token string">'text'</span><span class="token punctuation">,</span> <span class="token string">'text2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STRCMP</span><span class="token punctuation">(</span><span class="token string">'text2'</span><span class="token punctuation">,</span> <span class="token string">'text'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STRCMP</span><span class="token punctuation">(</span><span class="token string">'text'</span><span class="token punctuation">,</span> <span class="token string">'text'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span></code></pre>
     </div>
     <p>
      <a class="link" href="string-comparison-functions.html#function_strcmp">
       <code class="literal">
        STRCMP()
       </code>
      </a>
      performs the
            comparison using the collation of the arguments.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33750731"><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">SET</span> <span class="token variable">@s1</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'x'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_ai_ci<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@s2</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'X'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_ai_ci<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@s3</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'x'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_as_cs<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@s4</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'X'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_as_cs<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STRCMP</span><span class="token punctuation">(</span><span class="token variable">@s1</span><span class="token punctuation">,</span> <span class="token variable">@s2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">STRCMP</span><span class="token punctuation">(</span><span class="token variable">@s3</span><span class="token punctuation">,</span> <span class="token variable">@s4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> STRCMP(@s1, @s2) <span class="token punctuation">|</span> STRCMP(@s3, @s4) <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                0 <span class="token punctuation">|</span>               <span class="token punctuation">-</span>1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <p>
      If the collations are incompatible, one of the arguments
            must be converted to be compatible with the other. See
      <a class="xref" href="charset-collation-coercibility.html" title="12.8.4 Collation Coercibility in Expressions">
       Section 12.8.4, “Collation Coercibility in Expressions”
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68362147"><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">SET</span> <span class="token variable">@s1</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'x'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_ai_ci<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@s2</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'X'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_ai_ci<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@s3</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'x'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_as_cs<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@s4</span> <span class="token operator">=</span> _utf8mb4 <span class="token string">'X'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_as_cs<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">--&gt;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STRCMP</span><span class="token punctuation">(</span><span class="token variable">@s1</span><span class="token punctuation">,</span> <span class="token variable">@s3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1267 (HY000)<span class="token punctuation">:</span> Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT)
and (utf8mb4_0900_as_cs,IMPLICIT) for operation 'strcmp'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STRCMP</span><span class="token punctuation">(</span><span class="token variable">@s1</span><span class="token punctuation">,</span> <span class="token variable">@s3</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_ai_ci<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> STRCMP(@s1, @s3 COLLATE utf8mb4_0900_ai_ci) <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                                           0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
