Обсуждение: Randomize Result Set Order

Поиск
Список
Период
Сортировка

Randomize Result Set Order

От
Ryan Mahoney
Дата:
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
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.251 / Virus Database: 124 - Release Date: 4/26/01

Re: Randomize Result Set Order

От
merlyn@stonehenge.com (Randal L. Schwartz)
Дата:
>>>>> "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/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: Randomize Result Set Order

От
Bruce Momjian
Дата:
> >>>>> "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