I want to get only distinct rows with their respective AnsId
,
like Qid: 01 have last AnsId: 01
I have following data structure,
Qid Time AnsId
01 2011-09-26 12:55:10 01
02 2011-09-26 12:58:32 03
03 2011-09-26 12:59:05 02
01 2011-09-26 01:02:10 01
03 2011-09-26 01:30:10 01
02 2011-09-26 01:59:10 02
I have written following query but it returns all the rows:
SELECT DISTINCT Qid, Time, AnsId
FROM table
ORDER BY Time DESC
Then what is missing part in the select query?