Canman2005 Posted May 2, 2010 Share Posted May 2, 2010 Hi all I have the following database table ID VALUE 1 Apple 2 Microsoft 3 Mobiles 4 MP3s 5 Laptops I use a "SELECT" query in my PHP to get those results. Is it possible to "ORDER" my results by ID number 2 first ID number 1 second and then the remainder of the results in a A-Z order so the above would look like ID VALUE 2 Microsoft 1 Apple 5 Laptops 3 Mobiles 4 MP3s I tried ORDER BY (CASE WHEN `id` = 2 THEN 0 WHEN `id` = 1 THEN 2 END), `value` ASC But that doesn't seem to work no matter how much I tweak it around Any help would be great Thanks Ed Link to comment https://forums.phpfreaks.com/topic/200481-complex-order-by-help/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 What difference would that make? You can easily add a new column called "ordering" if you want to order them in a particular order. You can still do it using UNION. Just select the first 2 in descending order, then UNION it with the rest ordered by descending. Link to comment https://forums.phpfreaks.com/topic/200481-complex-order-by-help/#findComment-1052041 Share on other sites More sharing options...
Canman2005 Posted May 2, 2010 Author Share Posted May 2, 2010 It's just that I want to show some rows at the top of the list. I guess if it's not easy i'll have to think of another route Link to comment https://forums.phpfreaks.com/topic/200481-complex-order-by-help/#findComment-1052052 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 It is easy. Link to comment https://forums.phpfreaks.com/topic/200481-complex-order-by-help/#findComment-1052055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.