在DB2中, 使用FETCH FIRST子句限制返回行數:
select * from emp fetch first 5 rows only
使用RAND與ORDER BY和FETCH FIRST來獲取隨機條數
select * from emp order by rand() fetch first 5 rows only
在MySQL和PostgreSQL中, 使用LIMIT:
select * from emp limit 5
MySQL中獲取隨機行數:
select * from emp order by rand() limit 5
PostgreSQL中獲取隨機行數:
select * from emp order by random() limit 5
在Oracle中, 在WHERE子句中通過使用ROWNUM來限制行數:
select * from emp where rownum <= 5
select *
from (
select ename, job from emp order by dbms_random.value()
)
where rownum <= 5
在SQL Server中, 使用TOP來限制返回行數:
select top 5 * from emp
select top 5 ename, job from emp order by newid()
posted on 2008-07-15 20:50
周銳 閱讀(628)
評論(0) 編輯 收藏 所屬分類:
MySQL 、
Oracle 、
SQL Server