pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
To: emilu@encs.concordia.ca
Cc: pgsql-sql@postgresql.org
Subject: Re: how to get row number in select query
Date: Thu, 27 Jan 2011 15:02:24 -0000
Message-ID: <090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt> (raw)
References: <4D4047C1.5030208@encs.concordia.ca>
	<D25246ED495942DD8E5777F5F9439DD0@marktestcr.marktest.pt>
	<4D4181E9.2000305@encs.concordia.ca>




> 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.
>



view thread (8+ messages)  latest in thread

Message-ID: <090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt>
Permalink:  ../090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt/
Also on:    postgresql.org/message-id/090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt

 · 

reply

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: oliveiros.cristina@marktest.pt, emilu@encs.concordia.ca
  Subject: Re: how to get row number in select query
  In-Reply-To: <090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt>

* 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