Re: selecting random row - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: selecting random row
Date
Msg-id 20020402174255.C4927@svana.org
Whole thread Raw
In response to selecting random row  (Heiko Klein <Heiko.Klein@met.no>)
List pgsql-general
On Tue, Apr 02, 2002 at 06:57:21AM +0000, Heiko Klein wrote:
> Hi,
>
> out of a table i.e. people:
> id last first sex age address
>
> I would like to select a random id. Id's are a sequence, but some
> peoble have been deleted, so there are several id-holes in the
> table.
>
> Furthermore, I would like to specify the random person, like
>
> select 'random person id' from table where age > 60 and sex = 'm';

select * from table where age > 60 and sex = 'm' order by random() limit 1;

IIRC

HTH,
--
Martijn van Oosterhout <kleptog@svana.org>   http://svana.org/kleptog/
> Ignorance continues to thrive when intelligent people choose to do
> nothing.  Speaking out against censorship and ignorance is the imperative
> of all intelligent people.

pgsql-general by date:

Previous
From: "Dominic J. Eidson"
Date:
Subject: Re: Errors when running vacuumdb...
Next
From: Daniel Lundin
Date:
Subject: Re: selecting random row