I am trying to query from a table like this:
ID | product | revenue | data | device |
---|---|---|---|---|
01 | A | 10 | 2022-06-17 08:02:00.693 | mobile |
01 | A | 10 | 2022-06-17 10:02:00.693 | desk |
03 | G | 10 | 2022-06-17 09:02:00.693 | mobile |
03 | G | 10 | 2022-06-17 10:02:00.693 | desk |
As you can see the table contains duplicates for ID, product and revenues. I would like to select the duplicate with the most oldest date like this:
ID | product | revenue | data | device |
---|---|---|---|---|
01 | A | 10 | 2022-06-17 08:02:00.693 | mobile |
03 | G | 10 | 2022-06-17 09:02:00.693 | mobile |
I'm looking for an efficient query, I tried with the statement TOP, but it doesn't work
Database: T-SQL