Each country with last (id)

code country
(1) Korea
(2) China
(3) Japan
(4) Russia
(5) America
(6) Japan
(7) China
(8) America
(9) Russia
(10) China
(11) Russia
(12) Japan
(13) Korea
(14) Korea
(15) Russia
(16) Japan
(17) America
(18) Korea
(19) Japan
(20) America[/code]
I have myTable like the above.
I like to call each country with the last ID.

my target result is below

code America
(19) Japan
(18) Korea
(15) Russia
(10) China
[/code]

I tried “group by country” , but I failed to get my target result above.

code

select id, country from myTable group by country order by id desc

result

code America
(4) Russia
(3) Japan
(2) China
(1) Korea[/code]

I also tried “distinct(country)”, but failed too…

[quote=“joon1, post:1, topic:223658, full:true”]I also tried “distinct(country)”, but failed too…
[/quote]
DISTINCT is ~not~ a function

use MAX(id) instead of id in your GROUP BY query

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.