SQL: How can I order null and empty entries to the front in an orderby? SQL: How can I order null and empty entries to the front in an orderby? sql sql

SQL: How can I order null and empty entries to the front in an orderby?


ORDER BY     CASE     WHEN Name IS NULL THEN 1     WHEN Name = ''    THEN 2     ELSE 3     END DESC,     Name ASC


You can do it like this:

ORDER BY CASE WHEN Name IS NULL then 3 WHEN Name = '' THEN 2 ELSE 1 END, Name

It will order with by the number in the case first and afterwords by the Name.


ORDER BY CASE     WHEN Name IS NULL THEN 1     WHEN Name = '' THEN 2     ELSE 3END DESC,Name ASC