List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:September 18 1999 11:54am
Subject:Re: SELECT Random sets possible?
View as plain text  
On Sat, 1999-09-18 02:57:53 +0300, Michael Widenius wrote:
> >> Is it possible to SELECT a random recordset out of a database?
[...]
> Another option is to do the following:
> 
> SELECT *,rand() as r from table ORDER BY r LIMIT 5
> 
> In this case you must just ignore the last column in your application.

For MySQL V3.22.19b (that's what I'm still using here) this doesn't
work!  One always gets the same five rows in the same order, though
column r shows different random numbers each time ...

I could get it to work by adding a table field to the rand() term:
  SELECT *, id*0+RAND() AS r FROM table ORDER BY r LIMIT 5;

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
Thread
SELECT Random sets possible?David Fallon16 Sep
  • Re: SELECT Random sets possible?Christian Mack17 Sep
    • Re: SELECT Random sets possible?Michael Widenius18 Sep
      • Re: SELECT Random sets possible?Martin Ramsch18 Sep
        • Re: SELECT Random sets possible?Michael Widenius19 Sep