8 messages in com.mysql.lists.mysqlRe: Sort Select by List| From | Sent On | Attachments |
|---|---|---|
| Keith Spiller | 16 Dec 2006 13:24 | |
| Keith Spiller | 16 Dec 2006 13:35 | |
| Pintér Tibor | 16 Dec 2006 13:52 | |
| Mark Leith | 16 Dec 2006 13:59 | |
| Dan Nelson | 16 Dec 2006 20:44 | |
| Dan Nelson | 16 Dec 2006 20:47 | |
| Mark Leith | 17 Dec 2006 04:05 | |
| Keith Spiller | 17 Dec 2006 11:20 |
| Subject: | Re: Sort Select by List![]() |
|---|---|
| From: | Keith Spiller (lare...@hosthive.com) |
| Date: | 12/17/2006 11:20:06 AM |
| List: | com.mysql.lists.mysql |
Thanks Dan,
It is a very small table. I really appreciate you help.
Keith
----- Original Message ----- From: "Dan Nelson" <dnel...@allantgroup.com> To: "Mark Leith" <mle...@mysql.com> Cc: "Pintér Tibor" <tib...@tibyke.hu>; "[MySQL]" <mys...@lists.mysql.com> Sent: Saturday, December 16, 2006 9:48 PM Subject: Re: Sort Select by List
In the last episode (Dec 16), Dan Nelson said:
In the last episode (Dec 16), Mark Leith said:
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;
More efficient would be to use the FIELD function:
SELECT * FROM team ORDER BY FIELD(office,"Exec","VP","Dir");
Oops. I only read the replies and not the original post. Assuming there are many other values for the "office" field, you might want
SELECT * FROM team WHERE office = 'Exec' UNION SELECT * FROM team WHERE office = 'VP' UNION SELECT * FROM team WHERE office = 'Dir';
-- Dan Nelson dnel...@allantgroup.com
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=lare...@hosthive.com




