title: SQL composite key query
body: <p>to reference this again <a href="https://stackoverflow.com/questions/501347/sql-products-productsales">SQL products/productsales</a></p>
  
  <p>how could i do something like that when the primary key is made up of two columns and not one?</p>
  
  <p>so products has two columns as PK, and productsales has two columns as FK.</p>
  
  <p>here is the solution with a 1-column key:</p>
  
  <pre><code>SELECT p.[name]
  FROM products p
  WHERE p.product_id in (SELECT s.product_id
      FROM productsales s
      WHERE s.[date] between @dateStart and @dateEnd
      GROUP BY s.product_id
      HAVING Sum(s.quantity) &gt; @X )
  </code></pre>