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

Order by in Select

From: Bernie Huang <bernie(dot)huang(at)ec(dot)gc(dot)ca>
To: PGSQL-SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Order by in Select
Date: 2000-07-20 00:25:59
Message-ID: 39764717.7B5EB600@ec.gc.ca (view raw or flat)
Thread:
Lists: 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

Attachment: bernie.huang.vcf
Description: text/x-vcard (315 bytes)

Responses

pgsql-sql by date

Next:From: Stephan SzaboDate: 2000-07-20 00:38:23
Subject: Re: Order by in Select
Previous:From: Rodger DonaldsonDate: 2000-07-19 21:46:43
Subject: Re: Database authentication and configuration

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