问题
In Oracle, usually query like this for paging.
SELECT * FROM (SELECT *, rownum rid FROM TABLEA WHERE rownum <= #pageend#)
WHERE rid > #pagestart#
However, there is no "rownum" function in Sybase DBMS.
How can I do that query exactlly same in Sybase?
I found some ways.
use "rowcount"
set rowcount 10
select * from TABLEA
use identity (make temp table)
SELECT *, ROWNUM=IDENTITY(8) INTO #TEMP FROM TABLEA
SELECT * FROM #TEMP WHERE ROWNUM < #pageend# AND ROWNUM >= #pagestart#
DROP TABLE #TEMP
these are not what I want.
rowcount is set at the session level and i don't want make temp table.
回答1:
If you have a unique id column on your table you could use SELECT TOP n
SELECT TOP 10 *
FROM tableA
WHERE id BETWEEN @start AND @end
回答2:
This will give you all the ids so you can use them in a select like "select * where id_column in (ids from query below)
"
select top 10 id_column from trade
where @whereClause
and id_column > 0 //keep replacing this with the max id from the result set
order by id_column
来源:https://stackoverflow.com/questions/1225889/how-can-i-do-paging-in-sybase-without-making-temp-table-oracle-rownum-issue