i want to select set of records in SQL Server table.
In SQL Server, I can do this:
select TOP 40,60 *
from sometable
order by name
I want to get the 40th to the 60th rows.
Thank you.
i want to select set of records in SQL Server table.
In SQL Server, I can do this:
select TOP 40,60 *
from sometable
order by name
I want to get the 40th to the 60th rows.
Thank you.
LIMIT exists in Oracle but with different arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
SELECT * FROM sometbl Order by name LIMIT 40,100; # Retrieve rows 41-100
Or you can proceed as;
SELECT * FROM
(
SELECT st.*, Row_Number() OVER (ORDER BY name) rn FROM sometable st
)
WHERE rn BETWEEN 40 AND 60;
Use Row_number
function and fetch the rows you need
WITH tmp AS
(SELECT *, ROW_NUMBER() OVER (ORDER BY a.name) AS 'rn', a.* FROM table a)
SELECT * FROM tmp WHERE rn BETWEEN 40 AND 60
Try this
SELECT * FROM
(
SELECT table.*, Row_Number() OVER (ORDER BY name) rank FROM table
)
WHERE rank BETWEEN 40 AND 60;
i did that like this query
WITH temp AS
( SELECT *, ROW_NUMBER() OVER (ORDER BY name) AS 'RowNumber'
FROM sometable
)
SELECT * FROM temp WHERE RowNumber BETWEEN 40 AND 60
Thank you for all comment.