Hey noman,
You can do this real easy in MySQL. Use the LIMIT and OFFSET keyword. Thats it you are done.
But in MSSQL there is no LIMIT and OFFSET function. Unfortunately there is no other in-build clause provided in MS SQL to do this.But the same feature can be achieved in MS SQL with a little trick.
Suppose you want to write a query to return values from 6 - 8 (6,7,8) ,this can be achieved by TOP clause in MSSQL.
This is very simple,
Results 6-8 would be the first 3 rows of a TOP 3 statement, with a nested query with a TOP 8 statement in the opposite order.
Consider the employees table in NorthWind database,
This query will fetch you rows from 6-8(6,7,8).
SELECT * FROM (SELECT TOP 3 *
FROM (SELECT TOP 8 *
FROM [Employees]
ORDER BY [EmployeeID] ASC) AS tbl1
ORDER BY EmployeeID DESC) AS tbl2
ORDER BY EmployeeID ASC
Note:
1. Use the Alias tbl1,tbl2
2. Tweak the ORDER BY for complex results.