首頁 >資料庫 >mysql教程 >order by newid() 随机查询_MySQL

order by newid() 随机查询_MySQL

WBOY
WBOY原創
2016-06-01 13:48:591125瀏覽

bitsCN.com

SQL Server:

Select TOP N * From TABLE Order By NewID()   
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By NewID()

Select TOP N * From TABLE Order By NewID()
NewID()函数将创建一个 uniqueidentifier 类型的唯一值。上面的语句实现效果是从Table中随机读取N条记录。

Access:

Select TOP N * From TABLE Order By Rnd(ID)    
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By Rnd(ID)  

Select TOP N * From TABLE Order By Rnd(ID) 
Rnd(ID) 其中的ID是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段(UserName)

Select TOP N * From TABLE Order BY Rnd(Len(UserName))   
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order BY Rnd(Len(UserName))

Select TOP N * From TABLE Order BY Rnd(Len(UserName))

MySql:

Select * From TABLE Order By Rand() Limit 10   
view plaincopy to clipboardprint?
Select * From TABLE Order By Rand() Limit 10

Select * From TABLE Order By Rand() Limit 10


postgreSQL:

select * from glxt022 order by random() limit 5   
view plaincopy to clipboardprint?
select * from glxt022 order by random() limit 5

bitsCN.com
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn