Search results for 'get random value by SQL'. 1 post(s) found.
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
ORDER BY RAND()
LIMIT 1
Select a random row with PostgreSQL:
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
ORDER BY RANDOM()
LIMIT 1
Select a random row with Microsoft SQL Server:
SELECT TOP 1 column FROM table
ORDER BY NEWID()
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
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
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1
Thanks Mark Murphy
Another posts included in "SQL"
| How can I increase MySQL max connections? (0) | 2008/03/19 |
Trackback : Cannot send a trackbact to this post.
-
Subject Baseball gambling th betting.
2009/02/19 11:38
Baseball gambling th betting. Baseball gambling.
-
Subject Online gambling getting started.
2009/02/20 16:54
Online gambling.
-
Subject Online gambling news.
2009/02/20 22:10
Poker news online gambling news. Gambling news online gambling and casinos. News solutions for online gambling. Online gambling news.
-
Subject different money making ideas
2010/01/29 04:51
moneyideas
-
Subject different money making ideas
2010/01/29 13:31
moneyideas
-
Subject different money making ideas
2010/01/31 16:42
moneyideas

Prev

Rss Feed