mySQL ORDER BY null before DESC

If you try to sort numbers by ABS -> DESC and intend to get the null or other specific values first use this order by

ORDER BY column IS NULL DESC, ABS(column) DESC //for NULL values

ORDER BY column='' DESC, ABS_(column) DESC //for anything else

Source: https://stackoverflow.com/questions/9307613/mysql-order-by-null-first-and-desc-after

Back to Top