Re: Problem with ORDER BY and random() ?

Поиск
Список
Период
Сортировка
От Mike Mascari
Тема Re: Problem with ORDER BY and random() ?
Дата
Msg-id 3F70CA98.2010809@mascari.com
обсуждение исходный текст
Ответ на Problem with ORDER BY and random() ?  (Jean-Francois.Doyon@CCRS.NRCan.gc.ca)
Список pgsql-general
Jean-Francois.Doyon@CCRS.NRCan.gc.ca wrote:

> Hello,
>
> I'm trying to retrieve a limited number of random rows, and order them by a
> column, and am not having any luck with that last part:
>
> SELECT * FROM tablename ORDER BY random(), id LIMIT 10

How about:

SELECT * FROM
(SELECT * FROM tablename ORDER BY random() LIMIT 10) AS data
ORDER BY id;

HTH,

Mike Mascari
mascarm@mascari.com



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

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Problem with ORDER BY and random() ?
Следующее
От: Jean-Francois.Doyon@CCRS.NRCan.gc.ca
Дата:
Сообщение: Re: Problem with ORDER BY and random() ?