title: MySQL Left join WHERE table2.field = "X"
body: <p>I have the following tables:</p>
  
  <p><strong>pages</strong>:</p>
  
  <pre><code>+------------+--------------+------+-----+---------+----------------+
  | Field      | Type         | Null | Key | Default | Extra          |
  +------------+--------------+------+-----+---------+----------------+
  | page_id    | int(11)      | NO   | PRI | NULL    | auto_increment |
  | type       | varchar(20)  | NO   |     | NULL    |                |
  | categories | varchar(255) | NO   |     | NULL    |                |
  | title      | varchar(255) | NO   | MUL | NULL    |                |
  | text       | longtext     | NO   | MUL | NULL    |                |
  +------------+--------------+------+-----+---------+----------------+
  </code></pre>
  
  <p><strong>custom</strong>:</p>
  
  <pre><code>+---------+------------------+------+-----+---------+-------+
  | Field   | Type             | Null | Key | Default | Extra |
  +---------+------------------+------+-----+---------+-------+
  | page_id | int(10) unsigned | NO   | PRI | NULL    |       |
  | key     | varchar(255)     | NO   | PRI | NULL    |       |
  | value   | longtext         | NO   |     | NULL    |       |
  +---------+------------------+------+-----+---------+-------+
  </code></pre>
  
  <p>I want to join the tables in a way where:<br>
  1) all the entries from the first table are returned <code>LEFT JOIN custom ON pages.page_id = custom.page_id</code><br>
  2) <code>pages.type IN ('type_a', 'type_b', 'type_c')</code><br>
  3) "key" from the second table has value "votes" <code>custom.key = 'votes'</code></p>
  
  <p>I made everything so far, but the third condition is the problem. If there isn't entry for <code>key = 'votes'</code> in table <strong>custom</strong> the query returns only these with entries. I want to return <code>NULL</code> if missing entries.  </p>
  
  <p>I need <code>key = 'votes'</code>, because I have other entries for this page_id where the key is not 'votes' and this duplicates the rows from <strong>pages</strong></p>