mysql - 2 rows having unique field and recent date -


table :

enter image description here

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

enter image description here

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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -