Randomize Result Set Order

Started by Ryan Mahoneyover 24 years ago3 messagesgeneral
Jump to latest
#1Ryan Mahoney
ryan@paymentalliance.net

Is there an easy way to randomize the order that records get returned in?

Don't imagine there is - but thought I'd ask ;)

Thanks

Ryan Mahoney

#2Randal L. Schwartz
merlyn@stonehenge.com
In reply to: Ryan Mahoney (#1)
Re: Randomize Result Set Order

"Ryan" == Ryan Mahoney <ryan@paymentalliance.net> writes:

Ryan> Is there an easy way to randomize the order that records get returned in?
Ryan> Don't imagine there is - but thought I'd ask ;)

order by random()

I even threw it into my latest Linux Magazine column, expounding the
virtues of the official Database of RedHat.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/&gt;
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

#3Bruce Momjian
bruce@momjian.us
In reply to: Randal L. Schwartz (#2)
Re: Randomize Result Set Order

"Ryan" == Ryan Mahoney <ryan@paymentalliance.net> writes:

Ryan> Is there an easy way to randomize the order that records get returned in?
Ryan> Don't imagine there is - but thought I'd ask ;)

order by random()

I even threw it into my latest Linux Magazine column, expounding the
virtues of the official Database of RedHat.

I still haven't figured out how that function call does this trick.
My guess is that because we can order by a function, it is calling
random() for every row and just sorting on that. In normal usage, the
functionm would reference database columns.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026