Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 733E71337B7A for ; Thu, 27 Jan 2011 11:02:33 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 85803-08 for ; Thu, 27 Jan 2011 15:02:26 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id A9A011337B4E for ; Thu, 27 Jan 2011 11:02:25 -0400 (AST) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id ZQ59LFV0; Thu, 27 Jan 2011 15:02:24 -0000 Message-ID: <090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt> From: "Oliveiros d'Azevedo Cristina" To: Cc: References: <4D4047C1.5030208@encs.concordia.ca> <4D4181E9.2000305@encs.concordia.ca> Subject: Re: how to get row number in select query Date: Thu, 27 Jan 2011 15:02:24 -0000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/104 X-Sequence-Number: 35051 > Hi Oliveiros, > Howdy! >> If it is to order in ascendent fashion by, say, lname, >> one possibility would be >> >> SELECT COUNT(b.*) as row_number, a.lname,a.gname >> FROM "Table1" a, "Table2" b >> WHERE a.lname >= b.lname >> GROUP BY a.lname,a.gname >> ORDER BY row_number >> >> If you want to order by gname just change the WHERE clause accordingly >> >> N.B. : This works as long as there is no repetition on the column you >> use to order. >> If there is, we'll need a way to tie break. What is your specific case? >> >> Also, note that this method is time consuming, and would work only for >> relatively small tables. >> AFAIK, version 8.3 doesn't have any "non-standard SQL" way to get a row >> number, but it is possible that something like that has been introduced >> in later versions... > > Thank you for the answer. I see psql8.4 has the method. I am not interest > in ordering any columns, but just a line num. >