Thursday, August 14, 2008

How to sort null values first using ORDER BY

This link helps to understand the sorting of null values better.


CASE WHEN(rd.riskdistributionflag LIKE 'Y' AND rd.fundingstatustypekey=2)
THEN 'RDU'
WHEN (rd.riskdistributionflag LIKE 'Y' AND rd.fundingstatustypekey=1)
THEN 'RDF'
END AS RDUF,

ORDER BY nvl(RDUF,'AAA')

The above query ensures the NULL rows are ordered first and then the data comes later.

This link helps to understand the sorting order

No comments: