在DB2中, 使用FETCH FIRST子句限制返回行數(shù):
select * from emp fetch first 5 rows only
使用RAND與ORDER BY和FETCH FIRST來獲取隨機條數(shù)
select * from emp order by rand() fetch first 5 rows only
在MySQL和PostgreSQL中, 使用LIMIT:
select * from emp limit 5
MySQL中獲取隨機行數(shù):
select * from emp order by rand() limit 5
PostgreSQL中獲取隨機行數(shù):
select * from emp order by random() limit 5
在Oracle中, 在WHERE子句中通過使用ROWNUM來限制行數(shù):
select * from emp where rownum <= 5
select *
from (
select ename, job from emp order by dbms_random.value()
)
where rownum <= 5
在SQL Server中, 使用TOP來限制返回行數(shù):
select top 5 * from emp
select top 5 ename, job from emp order by newid()