By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,610 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,610 IT Pros & Developers. It's quick & easy.

generate row number in result set?

P: n/a
I'm doing a simple SELECT with an ORDER BY clause, and I'd like to get the
rows back with a row number included. Something like this:

SELECT <????> POSITION, NAME, TOTAL FROM MYTABLE ORDER BY TOTAL DESC

So I want the rows in the result to be numbered 1, 2, 3, 4 etc. so it looks
like a numbered list. How do I achieve this is DB2?

Thanks, Dan
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Daniel Garrison wrote:
I'm doing a simple SELECT with an ORDER BY clause, and I'd like to get the
rows back with a row number included. Something like this:

SELECT <????> POSITION, NAME, TOTAL FROM MYTABLE ORDER BY TOTAL DESC

SELECT ROW_NUMBER() OVER (ORDER BY TOTAL DESC) AS POSITION, NAME, TOTAL
FROM MYTABLE ORDER BY TOTAL DESC

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.