Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql doubt 1

Status
Not open for further replies.

TTLTD

Programmer
Jul 10, 2003
5
IN
Hi all,
Is there any way to add serial no to the result of the sql select statement?

If the select returns 10 records then Ist record should have serial no 1,next no should have serial no 2 etc.

Regards
TTl
 
Try to select ROWNUM pseudocolumn also.

Regards, Dima
 
This seems like a good time to remind users that if they find a particular answer helpful or they think think that the answer qualifies as an expert answer, they should indicate it, by marking the post as such.

How? If you are registered user then you'll notice that each post is followed by a 3 links. The first is a link that starts with a purple star, and reads "Mark this post as a helpful/expert post!". Simply click on it, then click on the line in the pop-up window that reads "Click Here To Confirm This Action And Give ****'s Post A Star".

Many new and first-time users aren't aware of this, so I'll give sem a star, as it was obviously helpful to TTLTD.
 
Note that the ROWNUM may not be in sequence if you do an ORDER BY. This is because the ROWNUM is assigned before the result-set is sorted. A way around this is:

SELECT ROWNUM, Col_1, Col_2, Col_3, Col_n
FROM (SELECT Col_1, Col_2, Col_3, Col_n FROM Table_X ORDER BY Col_2);

This should work in ORACLE Version 9 and 8.1.7, but I'm not sure about earlier versions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top