Results 1 to 2 of 2

Thread: Random row list

  1. #1
    Join Date
    Dec 2003
    Location
    Topeka, Ks
    Posts
    4

    Question Unanswered: Random row list

    Is there a way to write SQL select statement to select a row randomly?

  2. #2
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    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).
    Last edited by Peter.Vanroose; 08-17-06 at 16:39.
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •