Re: SQL Question

From: "GIROIRE, Nicolas (COFRAMI)" <nicolas(dot)giroire(at)airbus(dot)com>
To: Alex <alex(at)meerkatsoft(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Question
Date: 2005-04-15 12:23:26
Message-ID: 5C40CD1E4697424ABDE3AC57CF1B22C62772B0@FR0-MAILMB20.res.airbus.corp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

For the first request (How can i select only the newest record for each ProdId ?), you can do :

select * from test."tableProd" u
where u."LastUpdate" = (select max(t."LastUpdate")
from test."tableProd" t
where u."ProdId" = t."ProdId")

-----Message d'origine-----
De : pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org]De la part de Alex
Envoy : vendredi 15 avril 2005 13:59
: pgsql-general(at)postgresql(dot)org
Objet : [GENERAL] SQL Question

Hi,

i have a table

ProdId | LastUpdate
-------+------------
100 | 2005-04-01
100 | 2005-03-01
100 | 2005-02-01
200 | 2005-04-01
200 | 2005-03-01
200 | 2005-02-01

- How can i select only the newest record for each ProdId ?

100 | 2005-04-01
200 | 2005-04-01

- How can i select to retrieve the last 2 dates in record

100 | 2005-04-01 | 2005-03-01
200 | 2005-04-01 | 2005-03-01

Thanks
Alex

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

This mail has originated outside your organization,
either from an external partner or the Global Internet.
Keep this in mind if you answer this message.

This e-mail is intended only for the above addressee. It may contain
privileged information. If you are not the addressee you must not copy,
distribute, disclose or use any of the information in it. If you have
received it in error please delete it and immediately notify the sender.
Security Notice: all e-mail, sent to or from this address, may be
accessed by someone other than the recipient, for system management and
security reasons. This access is controlled under Regulation of
Investigatory Powers Act 2000, Lawful Business Practises.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2005-04-15 12:48:41 Re: If statements on select
Previous Message Thomas Kellerer 2005-04-15 12:15:00 Re: SQL Question