<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="selecting-columns">
      </a>
      5.3.4.3 Selecting Particular Columns
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045325234704">
  </a>
  <a class="indexterm" name="idm46045325233248">
  </a>
  <p>
   If you do not want to see entire rows from your table, just
          name the columns in which you are interested, separated by
          commas. For example, if you want to know when your animals
          were born, select the
   <code class="literal">
    name
   </code>
   and
   <code class="literal">
    birth
   </code>
   columns:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56073422"><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 keyword">name</span><span class="token punctuation">,</span> birth <span class="token keyword">FROM</span> pet<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>
<span class="token output"><span class="token punctuation">|</span> name     <span class="token punctuation">|</span> birth      <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>
<span class="token output"><span class="token punctuation">|</span> Fluffy   <span class="token punctuation">|</span> 1993<span class="token punctuation">-</span>02<span class="token punctuation">-</span>04 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Claws    <span class="token punctuation">|</span> 1994<span class="token punctuation">-</span>03<span class="token punctuation">-</span>17 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Buffy    <span class="token punctuation">|</span> 1989<span class="token punctuation">-</span>05<span class="token punctuation">-</span>13 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Fang     <span class="token punctuation">|</span> 1990<span class="token punctuation">-</span>08<span class="token punctuation">-</span>27 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Bowser   <span class="token punctuation">|</span> 1989<span class="token punctuation">-</span>08<span class="token punctuation">-</span>31 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Chirpy   <span class="token punctuation">|</span> 1998<span class="token punctuation">-</span>09<span class="token punctuation">-</span>11 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Whistler <span class="token punctuation">|</span> 1997<span class="token punctuation">-</span>12<span class="token punctuation">-</span>09 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Slim     <span class="token punctuation">|</span> 1996<span class="token punctuation">-</span>04<span class="token punctuation">-</span>29 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Puffball <span class="token punctuation">|</span> 1999<span class="token punctuation">-</span>03<span class="token punctuation">-</span>30 <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></code></pre>
  </div>
  <p>
   To find out who owns pets, use this query:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa31180518"><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 keyword">owner</span> <span class="token keyword">FROM</span> pet<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>
<span class="token output"><span class="token punctuation">|</span> owner  <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>
<span class="token output"><span class="token punctuation">|</span> Harold <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Gwen   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Harold <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Benny  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Diane  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Gwen   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Gwen   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Benny  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Diane  <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></code></pre>
  </div>
  <a class="indexterm" name="idm46045325225456">
  </a>
  <p>
   Notice that the query simply retrieves the
   <code class="literal">
    owner
   </code>
   column from each record, and some of
          them appear more than once. To minimize the output, retrieve
          each unique output record just once by adding the keyword
   <code class="literal">
    DISTINCT
   </code>
   :
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa20087778"><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 keyword">DISTINCT</span> <span class="token keyword">owner</span> <span class="token keyword">FROM</span> pet<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>
<span class="token output"><span class="token punctuation">|</span> owner  <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>
<span class="token output"><span class="token punctuation">|</span> Benny  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Diane  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Gwen   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Harold <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></code></pre>
  </div>
  <p>
   You can use a
   <code class="literal">
    WHERE
   </code>
   clause to combine row
          selection with column selection. For example, to get birth
          dates for dogs and cats only, use this query:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa49234284"><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 keyword">name</span><span class="token punctuation">,</span> species<span class="token punctuation">,</span> birth <span class="token keyword">FROM</span> pet
       <span class="token keyword">WHERE</span> species <span class="token operator">=</span> <span class="token string">'dog'</span> <span class="token operator">OR</span> species <span class="token operator">=</span> <span class="token string">'cat'</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>
<span class="token output"><span class="token punctuation">|</span> name   <span class="token punctuation">|</span> species <span class="token punctuation">|</span> birth      <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>
<span class="token output"><span class="token punctuation">|</span> Fluffy <span class="token punctuation">|</span> cat     <span class="token punctuation">|</span> 1993<span class="token punctuation">-</span>02<span class="token punctuation">-</span>04 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Claws  <span class="token punctuation">|</span> cat     <span class="token punctuation">|</span> 1994<span class="token punctuation">-</span>03<span class="token punctuation">-</span>17 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Buffy  <span class="token punctuation">|</span> dog     <span class="token punctuation">|</span> 1989<span class="token punctuation">-</span>05<span class="token punctuation">-</span>13 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Fang   <span class="token punctuation">|</span> dog     <span class="token punctuation">|</span> 1990<span class="token punctuation">-</span>08<span class="token punctuation">-</span>27 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Bowser <span class="token punctuation">|</span> dog     <span class="token punctuation">|</span> 1989<span class="token punctuation">-</span>08<span class="token punctuation">-</span>31 <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></code></pre>
  </div>
 </div>
 <br/>
</div>
