praveenhotha Posted December 6, 2010 Share Posted December 6, 2010 Hi I would like to sort a list of numbers in descending order but if the value is 0, they should appear at the beginning of the list. How can I implement this in query. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/220859-order-by-with-conditions/ Share on other sites More sharing options...
bh Posted December 7, 2010 Share Posted December 7, 2010 Hi, its a bit tricky. I tried to implement the order by what you said. I figured out that you can use an expression in your ORDER BY clause. With the expression you can do the DESC order with 0s coming to first. Heres the query. I hope it helps. SELECT number FROM temptable ORDER BY number=0 DESC, number DESC; Link to comment https://forums.phpfreaks.com/topic/220859-order-by-with-conditions/#findComment-1143995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.