title: Mysql multiple joins to one table with different conditions -- where do they go?
body: <p>I am querying for some posts in the wordpress posts table and grabbing multiple meta values with it by joining the postmeta table multiple times. I also have a number of conditions for both post columns and meta values. The query seems to be working but I am curious if I have put the conditions in the correct place. Comparing the following queries, which will get me the post ids and their associated meta most effectively/efficiently?</p>
  
  <p>This one:</p>
  
  <pre><code>SELECT a.ID as `post_id`, b.meta_value as `metaval1`, c.meta_value as `metaval2`, d.meta_value as `metaval3`
  FROM posts AS a
  JOIN postmeta AS b ON (b.post_id = a.ID AND b.meta_key = 'metakey1')
  LEFT JOIN postmeta as c ON (c.post_id = a.ID AND c.meta_key = 'metakey2')
  LEFT JOIN postmeta as d ON (d.post_id = a.ID AND d.meta_key = 'metakey3')
  WHERE
      b.meta_value != 10
      AND a.post_status = 'pending'
      AND a.post_date &lt; '2013-03-07 00:00:00'
      AND a.post_type = "post"
  ORDER BY a.post_date DESC
  LIMIT 100;
  </code></pre>
  
  <p>OR this one:</p>
  
  <pre><code>SELECT a.ID as `post_id`, b.meta_value as `metaval1`, c.meta_value as `metaval2`, d.meta_value as `metaval3`
  FROM posts AS a
  JOIN postmeta AS b ON (b.post_id = a.ID)
  LEFT JOIN postmeta as c ON (c.post_id = a.ID)
  LEFT JOIN postmeta as d ON (d.post_id = a.ID)
  WHERE
      b.meta_key = 'metakey1'
      AND b.meta_value != 10
      AND c.meta_key = 'metakey2'
      AND d.meta_key = 'metakey3'
      AND a.post_status = 'pending'
      AND a.post_date &lt; '2013-03-07 00:00:00'
      AND a.post_type = "post"
  ORDER BY a.post_date DESC
  LIMIT 100;
  </code></pre>
  
  <p>Any advice would be appreciated :)</p>