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

Re: Order by in Select

From: "Stephan Szabo" <sszabo(at)kick(dot)com>
To: "Bernie Huang" <bernie(dot)huang(at)ec(dot)gc(dot)ca>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Order by in Select
Date: 2000-07-20 00:38:23
Message-ID: 010b01bff1e2$cfe02760$0c64010a@kick.com (view raw or flat)
Thread:
Lists: pgsql-sql
> What can I add to the above sql statement so that is fetches the
> specified id first in a sorted list?
> 
> eg: if $specified_id=5;
> I want: 5,5,5,1,2,3,3,4,4,4,6,6,7
> 
> I could have done it in two different sql statements where one fetches
> specified_id and the other fetches and sorts others, but I want to be
> able to do it in one sql statement to reduce time.

Umm, maybe something like:
select id from table order by 
case when id=$specified_id then <minimal value for type> else id end



In response to

pgsql-sql by date

Next:From: Nathan YoungDate: 2000-07-20 00:55:24
Subject: synchronizing databases
Previous:From: Bernie HuangDate: 2000-07-20 00:25:59
Subject: Order by in Select

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