Re: Help retrieving lastest record

From: Alex Pilosov <alex(at)pilosoft(dot)com>
To: Steve Meynell <steve(at)candata(dot)com>
Cc: Postgresql Mailing List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Help retrieving lastest record
Date: 2001-02-16 20:50:32
Message-ID: Pine.BSO.4.10.10102161549470.13453-100000@spider.pilosoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Get an SQL book.

select * from basket
where date=(select max(date) where fruit='Apples)
and fruit='Apples';

On Thu, 15 Feb 2001, Steve Meynell wrote:

> Ok what I am trying to do is select out of the database the latest
> record meeting a certain criteria.
>
> Example:
>
> Number | Fruit | Date
> 15 Apples July 20, 1999
> 20 Oranges June 7, 2000
> 13 Pears Jan 31, 2000
> 17 Apples April 10, 1999
> Now what I need to do is select the oranges out because the date is the
> latest one, something like:
>
> select * from basket where max(date);
> This would yield me:
> 20 Oranges June 7, 2000
>
> I know this doesn't work but I need something like it.
> or something like
>
> select * from basket where max(date) and fruit='Apples';
> This would yield me:
> 15 Apples July 20, 1999
>
> Thank you in advance,
>
>
> --
> Steve Meynell
> Candata Systems
>
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-02-16 21:00:56 Re: Help Retrieving Latest Record
Previous Message Andrew Perrin 2001-02-16 20:47:13 Re: Help retrieving lastest record