-:
SELECT TOP 50 PERCENT a, b, c FROM table
-:
SELECT TOP 50 a, b, c FROM table
, , ORDER BY ( , , ORDER BY, , ).
Paging (for example, returning a block of x rows of y) is more cumbersome in SQLServer than many other SQL relational databases (more cumbersome than all, to be honest), but can be done with ROW_NUMBER:
WITH OrderedTable AS
(
SELECT a, b, c, ROW_NUMBER() OVER (ORDER BY d) as rowNumber
FROM table
)
SELECT a, b, c FROM OrderedTable
WHERE rowNumber between 31 and 40
Selects a third set of ten rows, ordered by column d.
This last method is also necessary when the limit comes from a variable, because TOP does not allow something like TOP @number.
source
share