You are here: 首頁 PHP分享特區 各資料庫隨機選取

飛朵啦學習手札

本網站建議使用Firefox2.0以上,或是使用Goole瀏覽器來瀏覽,並使用1024x768解析度來觀看.

各資料庫隨機選取

E-mail 列印 PDF

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

最近更新 ( 週二, 22 五月 2012 17:02 )  
 

新增回應


驗證碼
更新