Re: simple query question: return latest

Поиск
Список
Период
Сортировка
От Jerry III
Тема Re: simple query question: return latest
Дата
Msg-id 6PUkd.24388$KJ6.19342@newsread1.news.pas.earthlink.net
обсуждение исходный текст
Ответ на simple query question: return latest  (Scott Frankel <leknarf@pacbell.net>)
Список pgsql-general
SELECT "date" FROM "table" WHERE "color" = 'red' ORDER BY "date" DESC LIMIT
1;

Don't worry about names, just quote your identifiers. They will stand out
and you can use anything you want.

Jerry

"Michael Glaesemann" <grzm@myrealbox.com> wrote in message
news:89C8EF0C-3447-11D9-8FE6-000A95C88220@myrealbox.com...
> 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>



В списке pgsql-general по дате отправления:

Предыдущее
От: Jan Wieck
Дата:
Сообщение: Re: PostgreSQL on Guest Host (VMWare)
Следующее
От: "Jerry III"
Дата:
Сообщение: Re: Last value inserted