Home > Archive > PostgreSQL SQL > December 2006 > Count field in query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Count field in query
lucas@presserv.org

2006-12-06, 7:18 pm

Hi all.
Is there any way to build a query with a field that has the IndexCount
of the query.
It's something like the number of the row returned (starting with 1).
Something like:

select * from mytable order by name;
id | name | CountField
7 | KK | 1
98 | LL | 2
5 | ZZ | 3

select * from mytable order by id;
id | name | CountField
5 | ZZ | 1
7 | KK | 2
98 | LL | 3

I was thinking to create a sequence:
create temporary sequence MYSEQUENCE increment 1 MINVALUE 1;
And put this sequence as field " nextval('mysequence'
)":
select *,nextval('mysequenc
e') from mytable;
But I think its not the best way to do this! Couse I need to set
sequence value to 1 everytime.

Can Someone help me?
Thanks
Lucas Vendramin (Brazil)

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com