List:General Discussion« Previous MessageNext Message »
From:Fred van Engen Date:December 10 2002 11:33am
Subject:Re: Select and Sort?
View as plain text  
On Tue, Dec 10, 2002 at 04:12:22PM +0500, Tariq Murtaza wrote:
> Thanks for help.....
> here is another solution for that...
> 
> SELECT if (Category = 'others', '999', 0) as priority, ID, Category FROM 
> TableName
> ORDER BY priority, Category
> 

That's right. It has the same problem regarding optimization and it
gives you another column in your result set (which you may or may not
want).

Regards,

Fred.


> Fred van Engen wrote:
> >On Tue, Dec 10, 2002 at 03:32:13PM +0500, Tariq Murtaza wrote:
> >
> >>I want to achieve recordset like below (sorting category by Name and 
> >>including 'Others' at the end),
> >>I want to do that by single query ;), any idea???
> >>
> >>
> >>ID	Category
> >>------------------------
> >>6	biochemistry
> >>62	Commerce
> >>95	chemistry
> >>2	Engg
> >>87	Ecommerce
> >>7	math
> >>45	physics
> >>1	Software Engg	
> >>5	Others
> >>
> >
> >
> >Try something like this:
> >
> >SELECT id, category from mytable order by 
> >concat(if(id=5,'B','A'),category);
> >
> >Only problem is that it won't optimize, so use this on small tables only.
> >
> >
> >Regards,
> >
> >Fred.
> >
> 
> 
> 

-- 
Fred van Engen                              XB Networks B.V.
email: fred.van.engen@stripped                Televisieweg 2
tel: +31 36 5462400                         1322 AC  Almere
fax: +31 36 5462424                         The Netherlands
Thread
Select and Sort?Tariq Murtaza10 Dec
  • Re: Select and Sort?Fred van Engen10 Dec
  • Re: Select and Sort?Tariq Murtaza10 Dec
    • Re: Select and Sort?Fred van Engen10 Dec
    • RE: Select and Sort?Adolfo Bello10 Dec
  • Re: Select and Sort?Harald Fuchs10 Dec
  • Re: Select and Sort?Harald Fuchs10 Dec