mysql - 2 rows having unique field and recent date -
table :
i new query writing. stuck on retrieving 2 rows above table. data date sorted in descending order 2 different topic_id. there won't third different topic_id.
so want retrieve 2 rows have different topic_id, 1 data each topic_id having recent date.
the result be
try sql fiddle
http://sqlfiddle.com/#!2/f37963/9
select t1.* temp t1 join (select question_id, max(`date`) `date` temp group topic_id) t2 on t1.question_id= t2.question_id , t1.`date`= t2.`date`;
the logic find latest date in each group (subquery) , join table again retrieve other particulars.
Comments
Post a Comment