title: MySQL select products by filter
body: <p>I need to select IDs of products which have specific value_id.</p>
  
  <p>Table <code>products</code>:</p>
  
  <pre><code>| product_id | product_name | category_id | active |
  | 125        | notebook1    | 3           | 1      |
  | 236        | notebook2    | 3           | 1      |
  </code></pre>
  
  <p>Table <code>filters</code>:</p>
  
  <pre><code>| product_id | value_id | value_name |
  | 125        | 35       | 15" display|
  | 125        | 36       | 8GB RAM    |
  | 236        | 35       | 15" display|
  </code></pre>
  
  <p>This select works ok, if I want to select products IDs by one value_id:</p>
  
  <pre><code>SELECT DISTINCT p.product_id FROM products p
  LEFT JOIN filters f ON (p.product_id=f.product_id)
  WHERE p.active=1 AND p.category_id=3 AND f.value_id=36;
  </code></pre>
  
  <p>But when I check more filters on web, I need to select by more values, problem is that when I use:</p>
  
  <pre><code>SELECT DISTINCT p.product_id FROM products p
  LEFT JOIN filters f ON (p.product_id=f.product_id)
  WHERE p.active=1 AND p.category_id=3 AND f.value_id IN(35,36);
  </code></pre>
  
  <p>It gives me products which have 15" display <strong>OR</strong> 8GB RAM, I need products which have 15" display <strong>AND</strong> 8GB RAM. Thanks.</p>