title: LINQ: How do I select unique rows: max(id) with multiple columns?
body: <p>This is a &quot;toy&quot; example of a table that has many columns and 100s of thousands of rows.</p>
  <p>I want <em>FILTER OUT</em> any rows containing the same AcctNo, CustomerName and CustomerContact, but KEEP the ID for <em>ONE</em> of the duplicates (so I can access the record later).</p>
  <ul>
  <li><p>Example:</p>
  <pre><code>ID  AcctNo  CustomerName  CustomerContact
  1   1111    Acme Foods    John Smith
  2   1111    Acme Foods    John Smith
  3   1111    Acme Foods    Judy Lawson
  4   2222    YoyoDyne Inc  Thomas Pynchon
  5   2222    YoyoDyne Inc  Thomas Pynchon
  &lt;= For AcctNo 1111, I want to save IDs 2 and 3
  </code></pre>
  </li>
  <li><p>Fiddle:
  <a href="https://www.db-fiddle.com/f/bEECHi6XnvKAeXC4Xthrrr/1" rel="nofollow noreferrer">https://www.db-fiddle.com/f/bEECHi6XnvKAeXC4Xthrrr/1</a></p>
  </li>
  <li><p>Working SQL:</p>
  <pre><code>select max(id) as ID,AcctNo,CustomerName,CustomerContact
  from test
  where AcctNo = '11111'
  group by AcctNo,CustomerName,CustomerContact
  </code></pre>
  <p>OK: returns IDs 2 and 3:</p>
  <pre><code>ID AcctNo CustomerName CustomerContact
  -- ------ ------------ ---------------
  2  11111  Acme Foods   John Smith
  3  11111  Acme Foods   Judy Lawson
  </code></pre>
  </li>
  </ul>
  <p>Q: What's a LINQ equivalent for this SQL?</p>
  <ul>
  <li><p>Failed attempt:</p>
  <pre><code>IQueryable&lt;CustomerData&gt; query =
      from c in context.CustomerData
      where c.AcctNo == acctno
      group c by new { c.AcctNo , c.CustomerName, c.CustomerContact } into gcs
      select new { newID = gcs.Max(x =&gt; x.ID), gcs.AcctNo, gcs.CustomerName, gcs.CustomerContact }
  </code></pre>
  </li>
  </ul>