CASE use for NULL values ordered last

suggest change

in this way ‘0’ representing the known values ​​are ranked first, ‘1’ representing the NULL values ​​are sorted by the last:

SELECT ID
      ,REGION
      ,CITY
      ,DEPARTMENT
      ,EMPLOYEES_NUMBER
  FROM DEPT
  ORDER BY 
  CASE WHEN REGION IS NULL THEN 1 
  ELSE 0
  END, 
  REGION

ID | REGION |CITY |DEPARTMENT|EMPLOYEES_NUMBER| —— | —— |—— |—— |—— | 10 | Mid-Atlantic |Philadelphia |RESEARCH |13| 14 | Mid-Atlantic |New York |SALES |12 | 9 | Midwest |Chicago |SALES |8 | 12 | New England |Boston |MARKETING |9| 5 | West |Los Angeles |RESEARCH |11 | 15 | NULL |San Francisco |MARKETING |12| 4 | NULL |Chicago |INNOVATION |11 | 2 | NULL |Detroit |HUMAN RESOURCES |9|

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


CASE:
*CASE use for NULL values ordered last

Table Of Contents