title: MySQL left outer join with where clause - return unmatched rows
body: <p>I have two tables: <strong>pq</strong> and <strong>pe</strong>. I am trying to <code>LEFT OUTER JOIN</code> left table (<strong>pq</strong>) on right table (<strong>pe</strong>).</p>
  
  <ul>
  <li><strong>pq</strong> has primary key column <em>id</em></li>
  <li><strong>pe</strong> has two-column primary key, so it may have many pqid's or none</li>
  <li><strong>pe</strong>.uid column has to be used to extract only relevant data (<code>WHERE pe.uid = "12345"</code>)</li>
  <li><strong>pe</strong>.data should be joined to every <strong>pq</strong>.id row</li>
  </ul>
  
  <p>Here is how tables look:</p>
  
  <pre><code>pq:
  id | data
  1  | "abc"
  2  | "efg"
  
  pe:
  pqid | uid   | data
  2    | 54321 | "uvw"
  2    | 12345 | "xyz"
  </code></pre>
  
  <p>I can use the following query to match first 2 rows of <strong>pq</strong>.id to <strong>pe</strong>.pqid</p>
  
  <pre><code>SELECT pq.id, pq.data, pe.data FROM pq
      LEFT OUTER JOIN pe ON pq.id = pe.pqid
      ORDER BY pq.id LIMIT 2
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>pq.id | pq.data |  pe.data
  1     | "abc"   |  
  2     | "efg"   |  "uvw"
  </code></pre>
  
  <p>But if I use the WHERE statement like this:</p>
  
  <pre><code>SELECT pq.id, pq.data, pe.data FROM pq
      LEFT OUTER JOIN pe ON pq.id = pe.pqid
      WHERE pe.uid='12345'
      ORDER BY pq.id LIMIT 2
  </code></pre>
  
  <p>I only get one row with matching <strong>pe</strong>.pqid AND <strong>pe</strong>.uid:</p>
  
  <pre><code>pq.id | pq.data |  pe.data
  2     | "efg"   |  "xyz"
  </code></pre>
  
  <p>So with the WHERE clause I get the right <strong>pe</strong>.data, but I don't get <strong>pq</strong> rows that have no <strong>pq</strong>.id matching <strong>pe</strong>.pqid </p>
  
  <p>I need to get this:</p>
  
  <pre><code>pq.id | pq.data |  pe.data
  1     | "abc"   |  
  2     | "efg"   |  "xyz"
  </code></pre>