只查询一条记录:
mysql : select pk from tablelimit 1;
db2:select pk from tablefetch first 1 row only
oracle:select pk from tablewhere rownum<2;sqlserver:SELECTtop 1pkFROM table
mysql:
limit n 《==》limit 0,n
limit n+1,-1:表示从第n条至最后一条
limit n+1,m:表示从第n条开始往后查m条记录
查询min到max的记录:
select * from table where limit min-1,max-min;
sqlserver:
select top max-min *
from table
where id > (
select max(id)
from (select top max id from table order by id)
)
oralce:
SELECT * FROM
(
SELECT A.*, ROWNUM row
FROM (SELECT * FROM table) A WHERE ROWNUM <= max
)
WHERE row >= min
db2:
SELECT * FROM
(
Select id,other_colume rownumber() over(ORDER BY id ASC) AS rn
from table
) AS a1
WHERE a1.rn BETWEEN min AND max