I'm trying to write a query that returns only those rows that contain the latest date for each name.
So for example, this data:
Name | Date Sold | More Columns... |
---|---|---|
Bob | 2021-01-05 | |
Mike | 2021-01-18 | |
Susan | 2021-01-23 | |
Bob | 2021-02-04 | |
Susan | 2021-02-16 | |
Mike | 2021-03-02 |
Would produce this result:
Name | Date Sold | More Columns... |
---|---|---|
Bob | 2021-02-04 | |
Susan | 2021-02-16 | |
Mike | 2021-03-02 |
It's sort of like a GROUP BY
, but I'm not aggregating anything. I only want to filter the original rows.
How could I write such a query?
NOTE: In the end, this will be a SQL Server query but I need to write it using Entity Framework.
UPDATE: In reality, this is part of a much more complex query. It would be extremely difficult for me to implement this as a raw SQL query. If at all possible, I need to implement using Entity Framework.