This is a discussion on SELECT date ORDER BY question within the MySQL forums, part of the Database Server Software category; --> Hi there, I would like to sort a query by date in ascending order, however I do not want ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi there, I would like to sort a query by date in ascending order, however I do not want 'empty' dates to appear at the top, I want them to appear at the bottom instead. Is there any way I can do this with one SQL query? desired result: 2007-07-11 09:00:00 2007-07-12 10:00:00 2007-07-13 11:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 etc Many thanks, Steve |
| |||
| On 11 Jul, 09:20, steviemcg <stevie...@gmail.com> wrote: > Hi there, > > I would like to sort a query by date in ascending order, however I do > not want 'empty' dates to appear at the top, I want them to appear at > the bottom instead. > > Is there any way I can do this with one SQL query? > > desired result: > > 2007-07-11 09:00:00 > 2007-07-12 10:00:00 > 2007-07-13 11:00:00 > 0000-00-00 00:00:00 > 0000-00-00 00:00:00 > > etc > > Many thanks, > Steve SELECT IF(`date_field` = '0000-00-00 00:00:00', '1','0'), `date_field` FROM `a_table` ORDER BY 1,2 |
| ||||
| On Jul 11, 9:28 am, Captain Paralytic <paul_laut...@yahoo.com> wrote: > On 11 Jul, 09:20, steviemcg <stevie...@gmail.com> wrote: > > > > > Hi there, > > > I would like to sort a query by date in ascending order, however I do > > not want 'empty' dates to appear at the top, I want them to appear at > > the bottom instead. > > > Is there any way I can do this with one SQL query? > > > desired result: > > > 2007-07-11 09:00:00 > > 2007-07-12 10:00:00 > > 2007-07-13 11:00:00 > > 0000-00-00 00:00:00 > > 0000-00-00 00:00:00 > > > etc > > > Many thanks, > > Steve > > SELECT > IF(`date_field` = '0000-00-00 00:00:00', '1','0'), > `date_field` > FROM `a_table` > ORDER BY 1,2 Absolutely fantastic, thank you so much. |