List:General Discussion« Previous MessageNext Message »
From:Mark Leith Date:December 16 2006 9:59pm
Subject:Re: Sort Select by List
View as plain text  
Pintér Tibor wrote:
> Keith Spiller írta:
>> I'm wondering how I would turn three different queries:
>>
>>     SELECT * FROM team WHERE office = 'Exec'
>>     SELECT * FROM team WHERE office = 'VP'
>>     SELECT * FROM team WHERE office = 'Dir'
>>
>> Into one query with the sort order of office = 'Exec', 'VP', 'Dir'...
>> Thanks,
>>   
> order by right(office,1)
>
> or make an extra column for ordering

Or be really smart :)

SELECT * FROM team ORDER BY office='Exec' DESC,office='VP' 
DESC,office='Dir' DESC;

Not many people know that you can order by literals as well ;)

Cheers,

Mark

-- 
Mark Leith, Support Engineer
MySQL AB, Worcester, England, www.mysql.com
Are you MySQL certified?  www.mysql.com/certification

Thread
Sort Select by ListKeith Spiller16 Dec
  • Re: Sort Select by ListKeith Spiller16 Dec
  • Re: Sort Select by ListPintér Tibor16 Dec
    • Re: Sort Select by ListMark Leith16 Dec
      • Re: Sort Select by ListDan Nelson17 Dec
        • Re: Sort Select by ListDan Nelson17 Dec
          • Re: Sort Select by ListMark Leith17 Dec
  • Re: Sort Select by ListKeith Spiller17 Dec