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 -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -