1 Replies - 1666 Views - Last Post: 30 May 2008 - 03:15 AM

#1 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Random row

Posted 16 January 2006 - 05:08 PM

Description: Just edit to fit your needs. Put in anything you want, but just leave "ORDER BY RAND()" and "LIMIT n" where they are. (LIMIT can be set to any number you want though.) Apparently this doesn't work on SQL*Plus. But keep in mind this was written and tested for MySQL.Get a random row from a table. Useful for just about anything where you need a random entry.
SELECT * FROM `sometable` WHERE 1 ORDER BY RAND() LIMIT 1;


Is This A Good Question/Topic? 0
  • +

Replies To: Random row

#2 Trogdor   User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Random row

Posted 30 May 2008 - 03:15 AM

The reason this does not work in a lot of (other) databases is that the rand() will be compiled with the rest of the statement. Thus, next time you execute the same query, the same (compiled) cashed statement will be executed, with the same value for rand(). That kinda spoils it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1