I am trying to get the last ids if user_handle is distinct with only 1 SQL query. Anyone knows how to do this?. I need that the SQL returns the ids (16149,16154). Thanks a lot.
Asked
Active
Viewed 56 times
-5
-
Challenge accepted marked it as a dupe :) – M Khalid Junaid Jan 12 '18 at 17:21
-
@MKhalidJunaid This is basic `MAX() .. GROUP BY`. – Paul Spiegel Jan 12 '18 at 17:23
-
Please share your attempt at this problem. – Nishant Jan 12 '18 at 17:23
-
@PaulSpiegel Linked question has accepted answer with both approaches max on column and max row per group – M Khalid Junaid Jan 12 '18 at 17:24
-
query: `select max(id) from handleuser group by user_handle order by id desc;` – ArifMustafa Jan 12 '18 at 17:33
1 Answers
2
How about using max()
?
select max(id), user_handle
from t
group by user_handle;

Gordon Linoff
- 1,242,037
- 58
- 646
- 786