title: SQL: LIMIT executed before DISTINCT
body: <p>I am doing a custom WordPress query and I need to have pagination on the results. 
  For testing purposes limit is set to 2. When there are 4 unique results WP displays only 1 result on the first page and in the total of the results it misses the last result.</p>
  
  <p>I guess the problem is in the result of this query:</p>
  
  <pre><code>SELECT DISTINCT* 
  FROM wp_posts
  LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) 
  WHERE wp_posts.post_status ='publish'
  AND wp_posts.post_type ='directory_listing'
  AND wp_term_relationships.term_taxonomy_id
  IN ( 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82) 
  ORDERBY wp_posts.post_title ASC 
  LIMIT 0 , 2
  </code></pre>
  
  <p>When I execute this directly on MySQL it returns two duplicates instead of the two first unique results.</p>
  
  <p>Am I doing this the wrong way? How to solve this issue?</p>