Unix Technical Forum

SELECT date ORDER BY question

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:12 AM
steviemcg
 
Posts: n/a
Default SELECT date ORDER BY question

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:12 AM
Captain Paralytic
 
Posts: n/a
Default Re: SELECT date ORDER BY question

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 10:12 AM
steviemcg
 
Posts: n/a
Default Re: SELECT date ORDER BY question

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com