<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="charset-collate">
      </a>
      12.8.1 Using COLLATE in SQL Statements
     </h3>
    </div>
   </div>
  </div>
  <p>
   With the
   <code class="literal">
    COLLATE
   </code>
   clause, you can override
        whatever the default collation is for a comparison.
   <code class="literal">
    COLLATE
   </code>
   may be used in various parts of SQL
        statements. Here are some examples:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      With
      <code class="literal">
       ORDER BY
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56920788"><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> k
<span class="token keyword">FROM</span> t1
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> k <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      With
      <code class="literal">
       AS
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa81176091"><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> k <span class="token keyword">COLLATE</span> latin1_german2_ci <span class="token keyword">AS</span> k1
<span class="token keyword">FROM</span> t1
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> k1<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      With
      <code class="literal">
       GROUP BY
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43293884"><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> k
<span class="token keyword">FROM</span> t1
<span class="token keyword">GROUP</span> <span class="token keyword">BY</span> k <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      With aggregate functions:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22135611"><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">MAX</span><span class="token punctuation">(</span>k <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">)</span>
<span class="token keyword">FROM</span> t1<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      With
      <code class="literal">
       DISTINCT
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa31236424"><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 keyword">DISTINCT</span> k <span class="token keyword">COLLATE</span> latin1_german2_ci
<span class="token keyword">FROM</span> t1<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      With
      <code class="literal">
       WHERE
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa90915056"><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 operator">*</span>
<span class="token keyword">FROM</span> t1
<span class="token keyword">WHERE</span> _latin1 <span class="token string">'Müller'</span> <span class="token keyword">COLLATE</span> latin1_german2_ci <span class="token operator">=</span> k<span class="token punctuation">;</span></code></pre>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24368163"><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 operator">*</span>
<span class="token keyword">FROM</span> t1
<span class="token keyword">WHERE</span> k <span class="token operator">LIKE</span> _latin1 <span class="token string">'Müller'</span> <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      With
      <code class="literal">
       HAVING
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa48021277"><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> k
<span class="token keyword">FROM</span> t1
<span class="token keyword">GROUP</span> <span class="token keyword">BY</span> k
<span class="token keyword">HAVING</span> k <span class="token operator">=</span> _latin1 <span class="token string">'Müller'</span> <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
