How would I select all rows distinct on Forename and Surname and where there's a duplicate select the one with the higher SomeDate, then Id if still duplicates e.g.
For:
| Id | Forename | Surname | SomeDate | ---------------------------------------- | 1 | Bill | Power | 2011-01-01 | | 2 | James | Joyce | 2011-02-01 | | 3 | Peter | Lennon | 2011-03-01 | | 4 | John | Sellers | 2011-04-01 | | 5 | James | Joyce | 2011-05-01 | | 6 | Peter | Lennon | 2011-03-01 |
Results in:
| Id | Forename | Surname | SomeDate | ---------------------------------------- | 1 | Bill | Power | 2011-01-01 | | 4 | John | Sellers | 2011-04-01 | | 5 | James | Joyce | 2011-05-01 | | 6 | Peter | Lennon | 2011-03-01 |
How could I achieve this in
- T-SQL
- From a DataTable using C#