From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Yudie <yudie@axiontech.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: How to select and result row number??
Date: Mon, 16 Sep 2002 23:12:06 -0400 (EDT)
Message-ID: <200209170312.g8H3C6s16543@candle.pha.pa.us> (raw)
In-Reply-To: <001301c25b5a$2ef0ea40$8a01a8c0@yudie>
Yudie wrote:
> Hi,
>
> I would like to select and also give numbering in each record.
> Let say I have table 'City' with a 'cityname' column
>
> what is the select statement so I can get result records like this
>
> no cityname
> ---- --------------
> 1 NEW YORK
> 2 LOS ANGELES
> 3 HOUSTON
> 4 ....
> 5 ...
Good question. The only easy answer I have is the creation of a temp
table with a SERIAL column:
CREATE TEMP TABLE out (cnt SERIAL, other_cols...);
INSERT INTO out SELECT ... ORDER BY col;
SELECT * FROM out;
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: pgman@candle.pha.pa.us, yudie@axiontech.com
Subject: Re: How to select and result row number??
In-Reply-To: <200209170312.g8H3C6s16543@candle.pha.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox