mysql - How get MAX(id) for each username? -


i have mysql table:

enter image description here

how maximum id each username?

like above in image, desire rows username 'mostafa' or 'samsung' max id.

i testing lot of query, :

select max(id) , latitude, longitude 'users_geo' username = 'mostafa' 

this returns record max id username mostafa.

also test query:

select id, latitude, longitude `users_geo` username = 'samsung' having max( id ) limit 0 , 30 

this query return wrong result. query return row id=9 while max id user 'samsung' 21.

use mysql group by aggregate (group by) functions namely max in case.

select username, max(id) users_geo group username; 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -