mysql - select distinct id with their latest activity -


i have mysql table structure follows:

id         activity 6298    2015-06-25 11:39:35 11141   2015-06-25 11:24:52 11141   2015-06-25 11:24:10 15048   2015-06-25 11:23:08 

i want ids , latest activity :

so above example want this:

id         activity 6298    2015-06-25 11:39:35 11141   2015-06-25 11:24:52 15048   2015-06-25 11:23:08 

at moment have programatically go through each id , latest activity :

for each nextid in ids :     select * mytable id= nextid  order added desc limit  

note:

the table huge because each id has many activity(s).

question:

so question if there better way of doing it? example 1 single query return me each id latest activity.

just grouping. there no shorter/better way. minimal statement this:

select id, max(activity) activity tablename group id 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -