List:General Discussion« Previous MessageNext Message »
From:Stefan Kuhn Date:March 14 2013 10:14am
Subject:Aw: Re: Retrieve most recent of multiple rows
View as plain text  
> not all the rows, only the distinct q_id,
The subquery will give all distinct q_ids, but the select from in(subquery) will give
everything, because each row must have a q_id which is returned by the subquery. The
query after all says "select all rows where the q_id is one of the q_ids occuring in the
table" and this, of course, gives everything.
Also your select qid, max(atimestamp) is not doing what I think you want to do. I think
you want all raws where atimestamp is somehow a maximum. Now in your query max(atimesamp)
will return one single value and this will be used as a sort of constant. So if
max(atimestamp) is e. g. 5, you get effictively select qid, 5 from ... Qou will get all
rows with the constant becoming a row. You want to filter rows, so your condition must be
in where (this is a basic concept of sql). Somehow (this is not correct sql, just a hint)
it must be like select qid from kkk where atimestamp=max(atimestamp). If you want to
filter the condition must be in where, a function on a column behins select will not
filter.
I think you need to get a basic understanding of sql first, sorry if that sounds harsh
Stefan


On Wed, Mar 13, 2013 at 8:28 PM, Johan De Meersman <vegivamp@stripped>wrote:

> ------------------------------
>
> *From: *"Ananda Kumar" <anandkl@stripped>
> *Subject: *Re: Retrieve most recent of multiple rows
>
>
>
> select qid,max(atimestamp) from kkk where qid in (select distinct qid from
> kkk) group by qid;
>
>
> What use is that where statement? It just says to use all the rows in the
> table.
>
>
> --
> Unhappiness is discouraged and will be corrected with kitten pictures.
>


Thread
Aw: Re: Retrieve most recent of multiple rowsStefan Kuhn14 Mar
  • Re: Re: Retrieve most recent of multiple rowsAnanda Kumar14 Mar
    • Re: Retrieve most recent of multiple rowsJohan De Meersman14 Mar
      • Re: Retrieve most recent of multiple rowsMarcus Vinicius15 Mar
      • RE: Retrieve most recent of multiple rowsRick James18 Mar