从数据库表中随机获取N条记录的SQL语句

Oracle:

       select * from (select * from tableName order by dbms_random.value) where rownum < N

eg: select * from (select * from t_bd_person order by dbms_random.value) where rownum <= 5

MS SQLServer:

       select top N * from tableName order by newid()

 

My SQL:

       select * from tableName order by rand() limit N

eg:select * from t_bd_person order by rand() limit 5


转自:http://blog.csdn.net/senton/article/details/4404101

你可能感兴趣的:(db_oracle,后台,java,db_mysql)