Re: select a random record

Поиск
Список
Период
Сортировка
От Tod McQuillin
Тема Re: select a random record
Дата
Msg-id 20010901165829.L48344-100000@glass.pun-pun.prv
обсуждение исходный текст
Ответ на select a random record  (bj@zuto.de (Rainer Clasen))
Список pgsql-general
On Sat, 1 Sep 2001, Rainer Clasen wrote:

> This jukebox should offer a random play mode. It should take into account
> when the title was played the last time. My Idea is to submit the query
> returning the records ordered by their last time of play, ignore a random
> number of records, fetch one record and drop the result set.
>
> I'm wondering wether there is a more elegant way to fetch a random record
> from a result.

Sure, well, try this:

SELECT whatever FROM whereever WHERE whatever ORDER BY random() limit 5;

replace whatever and whereever with your selection criterie -- the order
by random() will randomise the results and limit 5 chooses only the first
5.
--
Tod McQuillin



В списке pgsql-general по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: 2 tables, joins and same name...
Следующее
От: A_Schnabel@t-online.de (Andre Schnabel)
Дата:
Сообщение: Re: select a random record