MySQL - Order By - Dates (multiple fields)
Posted: Wed Sep 01, 2010 12:31 pm
I have a table that contains (among other things) 2 date fields.
Either one or the other field must be filled out (or both).
Fields:
---------
SDate
ODate
Sample data:
------------
#1 SDate: 2010-02-01
#1 ODate: 2010-02-14
#2 SDate: 0000-00-00
#2 ODate: 2010-02-19
#3 SDate: 2010-02-23
#3 ODate: 0000-00-00
If I do an ORDER BY SDate DESC, ODate DESC it would return:
#3, #1, #2
This is because #2 ODate has not been entered.
But what I would like is:
#3, #2, #1
Basically I'd like to return the records in descending order (based on either field) regardless of whether or not both dates have been supplied.
Hopefully this makes sense...
Thanks in advance! Any help would be greatly appreciated! :)
Either one or the other field must be filled out (or both).
Fields:
---------
SDate
ODate
Sample data:
------------
#1 SDate: 2010-02-01
#1 ODate: 2010-02-14
#2 SDate: 0000-00-00
#2 ODate: 2010-02-19
#3 SDate: 2010-02-23
#3 ODate: 0000-00-00
If I do an ORDER BY SDate DESC, ODate DESC it would return:
#3, #1, #2
This is because #2 ODate has not been entered.
But what I would like is:
#3, #2, #1
Basically I'd like to return the records in descending order (based on either field) regardless of whether or not both dates have been supplied.
Hopefully this makes sense...
Thanks in advance! Any help would be greatly appreciated! :)