pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedOrder by in Select
2+ messages / 2 participants
[nested] [flat]
* Order by in Select
@ 2000-07-20 00:25 Bernie Huang <bernie.huang@ec.gc.ca>
2000-07-20 00:38 ` Re: Order by in Select Stephan Szabo <sszabo@kick.com>
0 siblings, 1 reply; 2+ messages in thread
From: Bernie Huang @ 2000-07-20 00:25 UTC (permalink / raw)
To: pgsql-sql
Hello,
I have a list of id's that I need to sort and fetch.
eg; 1,3,6,5,4,3,4,5,6,7,5,4,2
Select id
From table
Order By id Asc;
it becomes like: 1,2,3,3,4,4,4,5,5,5,6,6,7
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.
Any ideas? Thank you!
- Bernie
Attachments:
bernie.huang.vcf (text/x-vcard, 314B) download
begin:vcard
n:Huang;Bernie
tel;fax:(604)664-9195
tel;work:(604)664-9172
x-mozilla-html:TRUE
org:Environment Canada;Standards and Technology Services
adr:;;700-1200 West 73 Ave.;Vancouver;BC;V6P 6H9;Canada
version:2.1
email;internet:bernie.huang@ec.gc.ca
title:Programmer
x-mozilla-cpt:;0
fn:Bernie Huang
end:vcard
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Order by in Select
2000-07-20 00:25 Order by in Select Bernie Huang <bernie.huang@ec.gc.ca>
@ 2000-07-20 00:38 ` Stephan Szabo <sszabo@kick.com>
0 siblings, 0 replies; 2+ messages in thread
From: Stephan Szabo @ 2000-07-20 00:38 UTC (permalink / raw)
To: Bernie Huang <bernie.huang@ec.gc.ca>; +Cc: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-07-20 00:38 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-07-20 00:25 Order by in Select Bernie Huang <bernie.huang@ec.gc.ca>
2000-07-20 00:38 ` Stephan Szabo <sszabo@kick.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox