Dan
Dan

Reputation: 73

mysql shift rows at the bottom of the result set

I am trying to shift rows with value less than current date at the bottom of the result set. I've this query

SELECT 
r_id AS Id,
f_title AS Title,
f_desc AS Description,
f_upload_file AS File,
ABS(DAYOFYEAR(f_valid_date)- DAYOFYEAR(CURDATE())) AS Deadline,
f_added_on as 'Added On'
FROM t_documents
WHERE 
f_rec_status= TRUE
ORDER BY Deadline ASC

and it gives this result:

enter image description here

Any help will be appreciated.

Upvotes: 1

Views: 109

Answers (1)

John Woo
John Woo

Reputation: 263803

Try this,

ORDER BY (CASE WHEN Deadline IS NULL
               THEN 1 ELSE 0 END) ASC, Deadline ASC

Upvotes: 2

Related Questions