- How to
ORDER BYwith aCASE-Statement- first group: null values in date-column
Col1sorted by date-columnCol2 DESC - second group: not-null values in date-column-
Col1sorted byCol1 DESC
- first group: null values in date-column
I’ve tried following:
SELECT columns FROM tables WHERE condition
ORDER BY
case when Table1.Col1 IS NULL then 0 end, Table2.Col2 DESC,
case when Table1.Col1 IS NOT NULL then 1 end, Table1.Col1 DESC
But the sort order is wrong, the NOT NULL values are first(sorted by Col2 instead of Col1). I think i’ve missed a detail.
1 Answer