How can I get Records from 10-to15 I find some code in net Like
Select *
from Employee
LIMIT 10 to 15
but I am getting an error at Limit
How can I get Records from 10-to15 I find some code in net Like
Select *
from Employee
LIMIT 10 to 15
but I am getting an error at Limit
You can use offset and fetch next:
select e.*
from Employee e
order by ??
offset 9
fetch next 6 rows only;
Note that fetch is available from SQL Server 2012 onward.
Normally, you do this with an order by. The ?? is for the column/expression for ordering. Fetching with an offset doesn't make sense without an order by, because result sets are in an arbitrary order unless the ordering is explicit.
In earlier (supported) versions, I would recommend row_number():
select e.*
from (select e.*, row_number() over (order by ??) as seqnum
from Employee e
) e
where seqnum between 10 and 15;
alternatively, you can use "ROW_NUMBER()". See the following code sample from this stack overflow: Row Offset in SQL Server
SELECT col1, col2
FROM (
SELECT col1, col2, ROW_NUMBER() OVER (ORDER BY ID) AS RowNum
FROM MyTable
) AS MyDerivedTable
WHERE MyDerivedTable.RowNum BETWEEN @startRow AND @endRow