select * from tab where anwer_timestamp in (select max(anwer_timestamp)
from tab where q_id in (select distinct q_id from tab) group by q_id);


On Wed, Mar 13, 2013 at 6:48 PM, Norah Jones <nh.jone...@gmail.com> wrote:

> I have a table which looks like this:
>
>     answer_id  q_id  answer  qscore_id  answer_timestamp
>     1          10    Male    3          1363091016
>     2          10    Male    3          1363091017
>     3          11    Male    3          1363091018
>     4          10    Male    3          1363091019
>     5          11    Male    3          1363091020
>     6          12    Male    3          1363091020
>     7          11    Male    3          1363091025
>
> So I have multiple answers for the same questions (q_id). I want to be
> able to retrieve only ONE answer per question and that be the most recent
> answer.
> There should be THREE rows returned, which are all the most recent
> answered for that q_id:
>
>     4          10    Male    3          1363091019
>     6          12    Male    3          1363091020
>     7          11    Male    3          1363091020
>
>

Reply via email to