Is there a way with PostgreSQL to sort rows with NULL values in fields to the end of the selected table?
Like:
SELECT * FROM table ORDER BY somevalue, PUT_NULL_TO_END
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
NULLvalues are sorted last in default ascending order. You don’t have to do anything extra.The issue applies to descending order, which is the perfect inverse and thus sorts
NULLvalues on top.PostgreSQL 8.3 introduced
NULLS LAST:For PostgreSQL 8.2 and older or other RDBMS without this standard SQL feature:
FALSEsorts beforeTRUE, soNULLvalues come last, just like in the example above.See:
SELECT