-1

I am trying to solve a duplicate issue in SQL server.

I have a lot of duplicate records with the exact information except the column time like:

enter image description here

I would like to select the record that has the max datetime for each subset of duplicates.

I tried to use the MAX() aggregation but that does not work.

Any ideas?

Ethan
  • 876
  • 8
  • 18
  • 34
Reco Jhonatan
  • 1,503
  • 4
  • 23
  • 35
  • Actually, though, on second glance your question is simpler than the duplicate I suggested, and even the "at first glance" solution from [this answer](https://stackoverflow.com/questions/7745609/sql-select-only-rows-with-max-value-on-a-column/7745635#7745635) would work. – Ilmari Karonen Dec 08 '21 at 00:06
  • The suggested answer is much more complicated than this question requires. Is it too late to change it? – Marek P Dec 08 '21 at 00:22

2 Answers2

0

In MS SQL Server, you would do something like this:

SELECT [id], [name], MAX([date])
FROM [table_name]
GROUP BY [id], [name]
Marek P
  • 445
  • 3
  • 12
0
SELECT id, name, MAX(date) as maxdate FROM mytable GROUP BY id, name

This should give you exactly the results you describe, in SQL Server.

Tamora
  • 47
  • 5