Solved

order by date asc putting blank dates on the bottom

Posted on 2006-10-24
3
483 Views
Last Modified: 2008-02-01
Hi,

I'm doing a query where I want to sort the data by the column "shipdate".  The most recent ship dates should be on top.  Simple enough using order by date ASC.

Similar to this...

SELECT
name, dealer, orderid, shipdate
FROM tblOrders
ORDER BY shipdate ASC

HOWEVER, some of the shipdates are null and/or empty.  These ship dates are returning on the top of the returned query.  I want the rows with no ship date to appear on the BOTTOM of the query, after the rows that have a ship date in the proper order.

How can I do this?


0
Comment
Question by:benjamintr
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 50 total points
ID: 17798050
ORDER BY shipdate IS NULL OR shipdate = '', shipdate
0
 

Author Comment

by:benjamintr
ID: 17798111
That works!  Could you provide a quick explanation for me of what's going on?
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 17798303
IS NULL return 0 if the value is not null, 1 if it is. 0 sorts before 1, so we have all not null and not empty values before all null or empty values.  Then within those two groups, we sort by shipdate.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question