From: | "Thalis A(dot) Kalfigopoulos" <thalis(at)cs(dot)pitt(dot)edu> |
---|---|
To: | J C Lawrence <claw(at)kanga(dot)nu> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: |
Date: | 2001-10-08 14:09:47 |
Message-ID: | Pine.LNX.4.21.0110081007550.26266-100000@aluminum.cs.pitt.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
It's a simple select/group by:
select nid,type,max(version) from node group by nid,type;
It'd help reading the postgresql SQL tutorial to freshen you up.
cheers,
thalis
On Sun, 7 Oct 2001, J C Lawrence wrote:
>
> Given a table ala:
>
> CREATE TABLE "node" (
> "nid" integer NOT NULL
> "type" integer NOT NULL;
> "version" integer NOT NULL,
> );
>
> Where version defines is the count of the number of revisions to a
> given nid/type tuple.
>
> How could I construct a query which extracts only the rows with the
> largest version number for each nid/type combination? eg given:
>
> nid type version
> ---------------------
> 1 1 5
> 1 1 4
> 1 1 3
> 1 1 2
> 1 1 1
> 2 3 2
> 2 3 1
> 3 7 4
> 3 7 3
> 3 7 2
> 3 7 1
>
> I want a query which will return:
>
> nid type version
> ---------------------
> 1 1 5
> 2 3 2
> 3 7 4
>
> Is there a way without doing a temporary table and doing a bunch of
> SELECT INTOs>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-10-08 14:33:01 | Re: |
Previous Message | Andrej Falout | 2001-10-08 08:00:22 | [Announce] Aubit 4gl, Informix-4gl compatible OpenSource GNU compiler project |