- Архив списков рассылки pgsql-general

Поиск
Список
Период
Сортировка
От J C Lawrence
Тема
Дата
Msg-id 10793.1002523912@kanga.nu
обсуждение исходный текст
Ответы Re:  ("Thalis A. Kalfigopoulos" <thalis@cs.pitt.edu>)
Список 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 по дате отправления:

Предыдущее
От: Luke Vanderfluit
Дата:
Сообщение: blob
Следующее
От: Andrej Falout
Дата:
Сообщение: [Announce] Aubit 4gl, Informix-4gl compatible OpenSource GNU compiler project