title: SQL query to join two tables despite the other table may not have values
body: <p>I'm trying to query two Wordpress tables, ie. <code>posts</code> and <code>postmeta</code>.</p>
  
  <p>Basically the tables and rows I'm interested looks like this:  </p>
  
  <pre><code>| ---- ** posts ** ---- |    | -------- ** postmeta ** ---------- |
  | ID       | post_type  |    | post_id  | meta_key   | meta_value |
  |-----------------------|    |------------------------------------|
  | 1        | player     |    | 1        | number     | 10         |
  | 2        | player     |    | 2        | number     | 20         |
  | 3        | player     |    | 3        | othre_key  | aaa        |
  | 4        | other_type |    | 4        | other_key  | xxx        |
  | 4        | other_type |    | 5        | other_key  | yyy        |
  | 4        | other_type |    | 6        | other_key  | zzz        |
  </code></pre>
  
  <p>I want to get all posts where <code>post_type = player</code> and order them by <code>postmeta.meta_value</code> where the <code>postmeta.meta_key = number</code> whether or not the <code>postmeta</code> row exists.</p>
  
  <p>so far I've got this:  </p>
  
  <pre><code>SELECT a.ID, a.post_title, b.meta_value, b.meta_key
  FROM $wpdb-&gt;posts AS a
  INNER JOIN $wpdb-&gt;postmeta AS b
      ON a.ID = b.post_id
      AND b.meta_key = %s
  WHERE a.post_status = %s
      AND a.post_type = %s
  GROUP BY a.ID
  ORDER BY b.meta_value+(0) ASC, a.post_title ASC
  </code></pre>
  
  <p>...which returns the players that has a number postmeta associated with them.</p>
  
  <p>How do I append the players that doesn't have that postmeta to the result within same query so that the desired result would look something like this?  </p>
  
  <pre><code>| --- ** result ** ---- |
  | ID       | meta_value |
  |-----------------------|
  | 1        | 10         |
  | 2        | 20         |
  | 3        | null       |
  </code></pre>