title: Where to add DISTINCT to SQL subquery
body: <p>I want to select unique images from a database. I am using the following query which includes a specific image, <code>(ID=11)</code>, but I'm getting some repeated images:</p>
  
  <pre><code>$photo=mysql_query("SELECT A. * FROM (
  SELECT * FROM profile_images
  WHERE approved='N'  
  ORDER BY (ID = 11) DESC, RAND()      
  LIMIT $sn) 
  as A ORDER BY RAND()");
  </code></pre>
  
  <p>Where can I put <code>DISTINCT</code>? I have tried: </p>
  
  <pre><code>$photo=mysql_query("SELECT A. * FROM (
  SELECT DISTINCT FROM profile_images
  WHERE approved='N'  
  ORDER BY (ID = 11) DESC, RAND()      
  LIMIT $sn) 
  as A ORDER BY RAND()");
  </code></pre>
  
  <p>But I'm getting this error: </p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM profile_images WHERE approved='N' ORDER BY (ID = 11) DESC, RAND(' at line 2</p>
  </blockquote>