Re: select a random record - Mailing list pgsql-general

From A_Schnabel@t-online.de (Andre Schnabel)
Subject Re: select a random record
Date
Msg-id 00a501c132b4$b5052580$0201a8c0@aschnabel.homeip.net
Whole thread Raw
In response to select a random record  (bj@zuto.de (Rainer Clasen))
List pgsql-general
----- Original Message -----
From: "Rainer Clasen" <bj@zuto.de>
Subject: [GENERAL] select a random record


...
>
> 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.
>
> Rainer

The following select should do it:
SELECT title_name FROM titles
ORDER BY last_played DESC
LIMIT 1
OFFSET ( floor ( random () * 20);




pgsql-general by date:

Previous
From: Tod McQuillin
Date:
Subject: Re: select a random record
Next
From: Michael Meskes
Date:
Subject: Re: Embedded SQL vulnerability