Re: simple query question: return latest

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: Scott Frankel <leknarf(at)pacbell(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: simple query question: return latest
Date: 2004-11-12 01:09:44
Message-ID: 89C8EF0C-3447-11D9-8FE6-000A95C88220@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Scott,

On Nov 12, 2004, at 10:00 AM, Scott Frankel wrote:

> color | date
> --------+------------
> red | 2004-01-19
> blue | 2004-05-24
> red | 2004-04-12
> blue | 2004-05-24
>
>
> How do I select the most recent entry for 'red'?
>

SELECT color, MAX(date)
FROM giventable
WHERE color = 'red' -- omit this line if you'd like to see the latest
date for each color
GROUP BY color;

OT hint: You might want to take a look at the list of PostgreSQL
Keywords in the documentation and avoid using them (such as date) to
help you avoid naming issues in the future.

Hope this helps.

Michael Glaesemann
grzm myrealbox com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Neil Conway 2004-11-12 01:19:29 Re: oid size on 64 bit machine
Previous Message Scott Frankel 2004-11-12 01:00:46 simple query question: return latest