Friday, March 26, 2010

ROW_NUMBER() window function

0 comments
ROW_NUMBER() OVER function can be used as a function to limit rows by specifying no of rows to view.

SELECT * FROM
( SELECT
ROW_NUMBER() OVER (ORDER BY sort_key ASC) AS row_number,
COLUMNS
FROM tablename
) A(name of select statement)
WHERE row_number <= 10


0 comments: