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. Quote 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; Quote Link to comment https://forums.phpfreaks.com/topic/220859-order-by-with-conditions/#findComment-1143995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.