Re: selecting random row

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Heiko Klein <Heiko(dot)Klein(at)met(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: selecting random row
Date: 2002-04-02 07:42:55
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Lundin 2002-04-02 07:50:31 Re: selecting random row
Previous Message Dominic J. Eidson 2002-04-02 07:29:32 Re: Errors when running vacuumdb...