title: How to compare multiple rows of the same SQL table
body: <p>Assuming I have a SQL Server table that looks like this:</p>
  
  <pre><code>id   valA   valB   valC
  -----------------------
  1    1      2      3
  2    4      5      6
  3    7      8      9
  3    10     11     12
  4    13     14     15
  4    16     14     15
  </code></pre>
  
  <p>I want to compare rows to find those with certain data matching. In this case I want to identify rows with matching id, valB, and valC, so it should find only the last two rows. The contents of the valA column are ignored.  </p>
  
  <p>Then I want to delete one of the two rows and I will then adjust the valA column as needed.  My trouble is identifying the matching rows.  </p>
  
  <p>From a lot of other similar questions on this site, I tried various things similar to this:</p>
  
  <pre><code>SELECT DISTINCT 
      A.id
  FROM
      newtable A
  INNER JOIN 
      newtable B ON A.id = B.id
  WHERE
      A.valB = B.valB AND
      A.valC = B.valC
  </code></pre>
  
  <p>but I end up getting all four ids. I'm not sure why. Even if that worked, I'm still not sure how to proceed with the update and delete actions I need to take on all the matching rows found. Any suggestions? Thanks.</p>