If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Random row list

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-17-06, 11:35
jwedeking jwedeking is offline
Registered User
 
Join Date: Dec 2003
Location: Topeka, Ks
Posts: 4
Question Random row list

Is there a way to write SQL select statement to select a row randomly?
Reply With Quote
  #2 (permalink)  
Old 08-17-06, 15:20
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by jwedeking
Is there a way to write SQL select statement to select a row randomly?
Yes; essentially you base the row to be selected on a "random event" like the "current timestamp".

There has been a thread on this forum before with exactly this question.

E.g., with PostgreSQL, you can write
Code:
SELECT col
FROM tab
ORDER BY random()
LIMIT 1;
but this is clearly SQL "dialect"; there are standard SQL ways to do this (using e.g. the current timestamp).
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/

Last edited by Peter.Vanroose; 08-17-06 at 15:39.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On