Solved

order by date asc putting blank dates on the bottom

Posted on 2006-10-24
3
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to insert record into a table 2 58
How to update the value of duplicated records (except latest one) 2 38
mysql date time 14 52
Export Data from MySql Using PHP 16 67
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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