随机选择数据库某几行

SQL to Select a random row from a database table
来源:
http://www.petefreitag.com/item/466.cfm

There are lots of ways to select a random record or row from a database table. Here are some example SQL statements that don't require additional application logic, but each database server requires different SQL syntax.

Select a random row with MySQL:
Select column FROM table
orDER BY RAND()
LIMIT 1
Select a random row with PostgreSQL:
Select column FROM table
orDER BY RANDOM()
LIMIT 1
Select a random row with Microsoft SQL Server:
Select TOP 1 column FROM table
orDER BY NEWID()
Select a random row with IBM DB2
Select column, RAND() as IDX
FROM table
orDER BY IDX FETCH FIRST 1 ROWS ONLY
Thanks Tim

Select a random record with oracle:
Select column FROM
( Select column FROM table
orDER BY dbms_random.value )
Where rownum = 1



你可能感兴趣的:(oracle,sql,mysql,SQL Server,db2)