posts - 431,  comments - 344,  trackbacks - 0

在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 周锐 阅读(607) 评论(0)  编辑  收藏 所属分类: MySQLOracleSQL Server

只有注册用户登录后才能发表评论。


网站导航: