title: MySQL select join where AND where
body: <p>I have two tables in my database:</p>
  
  <p><strong>Products</strong></p>
  
  <ul>
  <li>id (int, primary key)</li>
  <li>name (varchar)</li>
  </ul>
  
  <p><strong>ProductTags</strong></p>
  
  <ul>
  <li>product_id (int)</li>
  <li>tag_id (int)</li>
  </ul>
  
  <p>I would like to select products having all given tags. I tried:</p>
  
  <pre><code>SELECT
      *
  FROM
      Products
  JOIN ProductTags ON Products.id = ProductTags.product_id
  WHERE
      ProductTags.tag_id IN (1, 2, 3)
  GROUP BY
      Products.id
  </code></pre>
  
  <p>But it gives me products having any of given tags, instead of having all given tags. Writing <code>WHERE tag_id = 1 AND tag_id = 2</code> is pointless, because no rows will be returned.</p>