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

randomized order in select?

From: Enver ALTIN <enver(dot)altin(at)frontsite(dot)com(dot)tr>
To: pgsql-sql(at)postgresql(dot)org
Subject: randomized order in select?
Date: 2004-03-10 16:48:17
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql

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

in PostgreSQL.
|          |
|          |  Enver ALTIN (a.k.a. skyblue)
|          |  Software developer, IT consultant
|    FRONT |
|==========|  FrontSITE Bilgi Teknolojisi A.Ş.


pgsql-sql by date

Next:From: DavidDate: 2004-03-10 16:58:04
Subject: Alter table
Previous:From: DavidDate: 2004-03-10 15:57:17
Subject: Re: changing constraints

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