SQL Server Select top 10-20 results?
WITH T AS
(
SELECT TOP 20 name,
row_number() OVER (ORDER BY id) AS RN
FROM Products
ORDER BY id
)
SELECT
MAX(CASE WHEN RN <=10 THEN name END) AS Col1,
MAX(CASE WHEN RN > 10 THEN name END) AS Col2
FROM T
GROUP BY RN % 10
Starting with SQL server 2012 order by offset/fetch feature:
SELECT *
FROM SomeTable
ORDER BY someIdField
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;
I would do this:
SELECT [columns] FROM [table names] ORDER BY [column name] DESC LIMIT 10 OFFSET 10;
This is simpler and less complex....
What do you guys think?
select top 10 wwwhid from wwwh where wwwhid not in(select top 10 wwwhid from wwwh)