sql - MySQL select all rows from table with distinct ID using newest timestamp -
basically,
id status timestamp 1 0 2 1 1 bad 2
i want have
id status timestamp 2 1 1 bad 2
returned me.
this because want know recent status of ids in table. i've tried naive like:
select * my_tbl grouping id order 'timestamp' desc;
but won't work, idea? i'm sure it's simple cannot figure out :/
try .. bring together much faster sub query.
select t1.* table t1 left bring together table t2 on t2.id=t1.id , t2.timestamp > t1.timestamp t2.id null.
mysql sql
No comments:
Post a Comment