From: | "Goutam Paruchuri" <gparuchuri(at)oneil(dot)com> |
---|---|
To: | "Scott Frankel" <leknarf(at)pacbell(dot)net>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: simple query question: return latest |
Date: | 2004-11-12 14:06:08 |
Message-ID: | B2C547DF42419645804F05B54290755ADC7CC4@DAYTONEX.oneilinc.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
If 2 days are equal for color red, you still would get 2 rows returned.
Maybe the below is accurate.
SELECT g.color, g.date, g.entered_by
FROM giventable g
WHERE g.color = 'red'
AND g.date =
(SELECT MAX(g2.date)
FROM giventable g2
WHERE g2.color = g.color
) LIMIT 1
> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Scott Frankel
> Sent: Thursday, November 11, 2004 11:13 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] simple query question: return latest
>
>
>
> ORDER BY DESC LIMIT 1 is much simpler and more readable than
> a sub-query.
> Though the sub-query approach looks to be a good template for
> ensuring more accurate results by being more explicit.
>
> Thanks to all who responded!
> Scott
>
>
>
> SELECT * FROM colortable WHERE color = 'red' ORDER BY date
> DESC LIMIT 1;
>
>
>
> SELECT g.color, g.date, g.entered_by
> FROM giventable g
> WHERE g.color = 'red'
> AND g.date =
> (SELECT MAX(g2.date)
> FROM giventable g2
> WHERE g2.color = g.color
> )
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo(at)postgresql(dot)org
>
Confidentiality Notice
The information contained in this e-mail is confidential and intended for use only by the person(s) or organization listed in the address. If you have received this communication in error, please contact the sender at O'Neil & Associates, Inc., immediately. Any copying, dissemination, or distribution of this communication, other than by the intended recipient, is strictly prohibited.
From | Date | Subject | |
---|---|---|---|
Next Message | Michelle Konzack | 2004-11-12 15:18:13 | How many secondary databases can I create? |
Previous Message | Matteo Beccati | 2004-11-12 11:22:00 | Re: query with table alias |