Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

I have a SQL table with a datetime field. The field in question can be null. I have a query and I want the results sorted ascendingly by the datetime field, however I want rows where the datetime field is null at the end of the list, not at the beginning.

Is there a simple way to accomplish that?

1 Answer

0 votes
by (40.4k points)

Try the code given below:

select My_Date

from My_Table

order by case 

when My_Date is null then 1 else 0 end, My_Date

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 25, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 22, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...