title: How to delete multiple rows with 2 columns as composite primary key in ms sql server
body: <p>I have a table named <strong>ProductLog</strong> <code>(RequestID, Date, Product, Price)</code>. Here <code>RequestID</code> and <code>Product</code> is composite primary key.</p>
  
  <p>Now there is a cleaning tool which cleans the product after some days. Priviously the cleaning was straight cut. If Date was less than 15 days then delete it. Now some situation comes like - suppose there is a product which logs 18 days back. Now if we delete data less that 15 days then it will delete that product. Every product data should be there cause it is used for some monitoring purpose. Now deletion requirement changed.</p>
  
  <p>Choose a product. </p>
  
  <ul>
  <li>If the product has record within 15 days then keep 15 days data and
  delete remaining.  </li>
  <li>If the product record is not within 15 days then don't delete the data.</li>
  </ul>
  
  <p>Now I am trying to use query like </p>
  
  <pre><code>select RequestID, Product from ProductLog where Date &lt; '201505161505'
  EXCEPT
  select RequestID, Product from ProductLog where Product not in (
      select distinct Product  from ProductLog where Date &gt;  '201505161505' 
  )
  </code></pre>
  
  <p>I am able to select the data which should be deleted. Now I have to delete it. As <code>RequestID</code> and <code>Product</code> is a composite primary key, I can't use <code>IN</code> for deletion. Does anyone have any idea how can I achieve this?</p>