Drixson Oseña
Drixson Oseña

Reputation: 3641

Mysql Sort empty value before ORDER BY ASC

I have a query result (please refer below)

Current Result:
Paid Date
0000-00-00
2010-05-01
2011-06-02
2013-07-08
0000-00-00

In this situation I want to show all the unpaid first(with 0000-00-00 stamp) but also I need to achieve something like this result

Goal Result:
Paid Date
0000-00-00
0000-00-00
2013-07-08
2011-06-02
2010-05-01

What SQL Query I will write to obtain this output?

Upvotes: 1

Views: 170

Answers (2)

Ashwini Agarwal
Ashwini Agarwal

Reputation: 4858

You can achieve this using find_in_set.

Something like.. ORDER BY find_in_set(date_field, '0000-00-00')

OR using field as FIELD(date_field, '0000-00-00') DESC

Upvotes: 3

Amir Bilal
Amir Bilal

Reputation: 457

Try this:

ORDER BY (date_column IS NULL), date_column ASC

Upvotes: 0

Related Questions