Skip to content Skip to sidebar Skip to footer

How To Order By 2 Columns Combining Coalesce?

I have a question about ordering a SQL table. And I can't find a solution on stack or google. My table 'Score' seems as follows: Name Total Tries Game1 Game2 Game3 --------

Solution 1:

Considering you have NULL instead of empty in Total based on the CASE statement in your order by. Try this Order by

ORDERBYCOALESCE(Total,99999999999) ASC,Tries ASC

99999999999 will make the NULL values to sort at the end and the other records will be ordered in ascending order

or

ORDERBYcasewhen Total isnullthen0else1enddesc,Total ASC,Tries ASC

Post a Comment for "How To Order By 2 Columns Combining Coalesce?"