SQL Order of Null
What is the order of null in sql? Nestle in close, and I'll tell you.
Show
dev=# SELECT 1 AS value
UNION
SELECT null AS value
ORDER BY value desc;
value
-------
1
(2 rows)
dev=# SELECT 1 AS value
UNION
SELECT 0 AS value
ORDER BY value desc;
value
-------
1
0
(2 rows)
Tell
asc
means smaller to bigger
desc
means bigger to smaller
0 is smaller than 1.
null is bigger than 1.
If order by desc
, nulls will be first.
If order by asc
, nulls will be last.