- Mailing list pgsql-general

From J C Lawrence
Subject
Date
Msg-id 10793.1002523912@kanga.nu
Whole thread Raw
Responses Re:  ("Thalis A. Kalfigopoulos" <thalis@cs.pitt.edu>)
List pgsql-general
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>

--
J C Lawrence
---------(*)                Satan, oscillate my metallic sonatas.
claw@kanga.nu               He lived as a devil, eh?
http://www.kanga.nu/~claw/  Evil is a name of a foeman, as I live.

pgsql-general by date:

Previous
From: Luke Vanderfluit
Date:
Subject: blob
Next
From: Andrej Falout
Date:
Subject: [Announce] Aubit 4gl, Informix-4gl compatible OpenSource GNU compiler project