List:General Discussion« Previous MessageNext Message »
From:Ananda Kumar Date:March 13 2013 1:43pm
Subject:Re: Retrieve most recent of multiple rows
View as plain text  
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.jones01@stripped> 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
>
>

Thread
Retrieve most recent of multiple rowsNorah Jones13 Mar
  • Re: Retrieve most recent of multiple rowsAnanda Kumar13 Mar
  • Re: Retrieve most recent of multiple rowsJohan De Meersman13 Mar
    • Re: Retrieve most recent of multiple rowsAnanda Kumar13 Mar
      • Re: Retrieve most recent of multiple rowsAnanda Kumar13 Mar
        • Re: Retrieve most recent of multiple rowsJohan De Meersman13 Mar
          • Re: Retrieve most recent of multiple rowsAnanda Kumar14 Mar
  • Re: Retrieve most recent of multiple rowshsv16 Mar