Recently one of my friend was faced a problem. He wants contact list in sorted order, but the issue is he wants sorting the table according to email columns where some records are without email value.
In that case sorting result is like this type
he fired this Query -
select id, lastname, email from contact order by email
When he tried to sort in descending order then result is -
he fired this Query -
select id, lastname, email from contact order by email DESC
In a descending case result was wrong. Result must be show where null email values are at the last.
Sorting are working on filled values not on Null value.
So,
I found the way of sorting values including null values. -
select id, lastname, email from contact order by email DESC NULLS LAST
Using this query you will get this type of result -
In that case sorting result is like this type
he fired this Query -
select id, lastname, email from contact order by email
When he tried to sort in descending order then result is -
he fired this Query -
select id, lastname, email from contact order by email DESC
In a descending case result was wrong. Result must be show where null email values are at the last.
Sorting are working on filled values not on Null value.
So,
I found the way of sorting values including null values. -
select id, lastname, email from contact order by email DESC NULLS LAST
Using this query you will get this type of result -
NULLS LAST is a keyword for including the null values in a order column.