Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come implementare LIMIT con SQL Server?

A partire da SQL SERVER 2005, puoi farlo...

USE AdventureWorks;
GO
WITH OrderedOrders AS
(
    SELECT SalesOrderID, OrderDate,
    ROW_NUMBER() OVER (ORDER BY OrderDate) AS 'RowNumber'
    FROM Sales.SalesOrderHeader 
) 
SELECT * 
FROM OrderedOrders 
WHERE RowNumber BETWEEN 10 AND 20;

o qualcosa del genere per le versioni 2000 e precedenti...

SELECT TOP 10 * FROM (SELECT TOP 20 FROM Table ORDER BY Id) ORDER BY Id DESC