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
Post a Comment