Skip site navigation (1) Skip section navigation (2)

Re: randomized order in select?

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Enver ALTIN <enver(dot)altin(at)frontsite(dot)com(dot)tr>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: randomized order in select?
Date: 2004-03-10 19:06:04
Message-ID: Pine.LNX.4.33.0403101205190.11278-100000@css120.ihs.com (view raw or flat)
Thread:
Lists: pgsql-sql
On Wed, 10 Mar 2004, Enver ALTIN wrote:

> Hi,
> 
> I have got a simple table like this:
> 
>         create table tips (
>         	id integer primary key unique,
>         	tiptext text
>         );
> 
> and, I've got a website where I'm willing to show these tips in a random
> order. Each visitor will get a randomly selected tip. So for now, I have
> to do 2 queries:
> 
> 	select id from tips
> 
> collect an ID list, choose one randomly and retrieve it. I wish I could
> do something like:
> 
> 	select tiptext from tips order by random limit 1

You mean like:

select * from table order by random();

That Works as far back as 7.2, maybe before.


In response to

pgsql-sql by date

Next:From: Andreas Joseph KroghDate: 2004-03-10 19:52:21
Subject: Inserting data in a table using sub-selects
Previous:From: Bruno Wolff IIIDate: 2004-03-10 19:02:50
Subject: Re: randomized order in select?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group