From: | Emi Lu <emilu(at)encs(dot)concordia(dot)ca> |
---|---|
To: | "Oliveiros d'Azevedo Cristina" <oliveiros(dot)cristina(at)marktest(dot)pt> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: how to get row number in select query |
Date: | 2011-01-27 14:32:09 |
Message-ID: | 4D4181E9.2000305@encs.concordia.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi Oliveiros,
> 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.
I'd like to get it from DB since displaytag _rowNum does not display row
num correctly: 1, 10, 11, 12.... 2, 3, 4, 5, 6...
Thanks,
--
Lu Ying
From | Date | Subject | |
---|---|---|---|
Next Message | Oliveiros d'Azevedo Cristina | 2011-01-27 15:02:24 | Re: how to get row number in select query |
Previous Message | Sim Zacks | 2011-01-27 14:15:37 | Re: Queyring for columns which are exist in table. |