Re: Order by in Select

From: Date: Thu, 20 Jul 2000 18:27:24 +0000
Subject: Re: Order by in Select
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-1361@lists.php.net to get a copy of this message
Modify your sequel query so it's something like: select id, (if id == 5 then 0, else 1) as idfirst from table order by idfirst, id asc; The part in ()'s is pseudo code... I don't remember the exact sequence, but I know you can do it in most of them... -philip In article <39772F0E.F698B8DA@ec.gc.ca>, Bernie Huang <bernie.huang@ec.gc.ca> wrote: >-=-=-=-=-=- > >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

« previous php.db (#1361) next »