Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8F3Jl738823 for ; Fri, 14 Sep 2001 23:19:47 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f8F3CQf65939 for pgsql-sql@postgresql.org; Fri, 14 Sep 2001 23:12:26 -0400 (EDT) (envelope-from news) From: missive@frontiernet.net (Lee Harr) X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Number the lines Date: Sat, 15 Sep 2001 03:12:26 +0000 (UTC) Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 30 Message-ID: <9nugup$20cg$1@news.tht.net> References: <70c8063b.0109140405.1895bf0d@posting.google.com> Reply-To: missive@hotmail.com X-Complaints-To: scrappy@hub.org User-Agent: slrn/0.9.7.0 (FreeBSD) To: pgsql-sql@postgresql.org X-Archive-Number: 200109/110 X-Sequence-Number: 4775 On 14 Sep 2001 05:05:49 -0700, Yoann wrote: > how can I number the result's lines of a sql query ? > > explaination : I have a query which return me a list of values. I need > to order them (it's ok, easy ;) and then number the lines. The goal is > then to extract, for example, "the third maximum value". > CREATE TABLE value (i integer); INSERT INTO i VALUES (1); INSERT INTO i VALUES (3); INSERT INTO i VALUES (2); INSERT INTO i VALUES (1); INSERT INTO i VALUES (5); INSERT INTO i VALUES (2); CREATE VIEW ordered AS SELECT i FROM value ORDER BY i DESC; BEGIN; CREATE SEQUENCE seq; SELECT nextval('seq') as n, i INTO TEMP TABLE t FROM ordered; SELECT i FROM t WHERE n=3; -- IANADBA, but something like this might work...