如果我们都这样写分页:
select t.*
from(
select fieldName,rownum rn
from tableName t
where t.fieldName = condition
and rownum <= a
) t
where rn > b
或者这样:
select t.*
from(
select fieldName,rownum rn
from tableName t
where t.fieldName = condition
) t
where rn <= a and rn > b
那就要注意了,这样的写法有可能会出现重复项。
正确的写法:
select fieldName...
from(
select n.*,ruwnum
from(
select t.*
from tableName t
where t.fieldName=condition
order by primaryKey
)n where rownum<=end)
where rn>=start