Tandem Posted August 14, 2006 Share Posted August 14, 2006 If i want to order some query results by a factor that has no sort of reasonable order, but i know which order they should be in e.g1. Dog2. Cat3. Lionor something like that, how would i go about doing that?If you need more information or i don't make sense, please ask/say.Thanks in advance for any help. Link to comment https://forums.phpfreaks.com/topic/17563-mysql-ordering/ Share on other sites More sharing options...
Barand Posted August 14, 2006 Share Posted August 14, 2006 You could use a SQL CASE statement[code]SELECT animal FROM mytableORDER BY CASE WHEN animal='Dog' THEN 1 WHEN animal='Cat' THEN 2 WHEN animal='Lion' THEN 3 ELSE 99END[/code] Link to comment https://forums.phpfreaks.com/topic/17563-mysql-ordering/#findComment-74801 Share on other sites More sharing options...
Tandem Posted August 14, 2006 Author Share Posted August 14, 2006 Awesome, thats exactly what i need, thanks. Link to comment https://forums.phpfreaks.com/topic/17563-mysql-ordering/#findComment-74802 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.