In our database, instead of creating empty NULL dates, they are '0000-00-00' (I know this sucks). How can I arrange them so that dates that are not '0000-00-00' are first ordered by ASC and then empty dates '0000-00-00' appear after?
NULL
'0000-00-00'
ASC
Thanks!
... ORDER BY CASE WHEN YourDateColumn = '0000-00-00' THEN 2 ELSE 1 END, YourDateColumn
Try below:
SELECT * FROM your_table ORDER BY (date_column='0000-00-00'), date_column ASC
OR
select * from your_table order by if(date_column='0000-00-00',1,0),date_column;
You can use CASE WHEN http://dev.mysql.com/doc/refman/5.0/en/case-statement.html
CASE WHEN
... ORDER BY (CASE WHEN date = '0000-00-00' THEN 1 ELSE 0 END) ASC, otherColumns asc, ...
ORDER BY (DateColumn = 0) , DateColumn
Source: https://habr.com/ru/post/1396931/More articles:xCode loads PhoneGap start page other than index.html - objective-cDelete everything after a space in a line - regexMySQL: access is denied for the user ... using password: YES - javaReturning a sequence of numbers in an optimized, thread-safe manner - c #Coldfusion error executing sql statement - coldfusionHow to repeat (loop) jQuery fadein - fadeout - fadein - jqueryPHP and file write permissions - phphttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1396934/going-from-net-35-to-4-seems-to-break-legacy-xaml&usg=ALkJrhj_5rdMJRl3ZiDlovA1g3Xou6XebQSet proxy username and password using Wininet in C # - c #How to register a new extension using QuickLook on Mac OS 10.7? - text-filesAll Articles