Re: Order By [blank]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a little weird looking, but should do the job.  Remember that items in your 'order by' can be manipulated conditionally.  In this case, I'm looking for NULL as well as '' (empty) and changing it to something that should come after all your normal alphabetical values, but it doesn't change what appears in your results.  This only affects the sorting:

select * from sometable order by if(ifnull(somecolumn, '') = '', 'ZZZZZZZZZZZZZZZZZZZZZZZZ', somecolumn)

Hope that helps.

-TG

= = = Original message = = =

I have this column in mysql:

A
F
D
[ empty ]
A
C

If I do an order by on that column, this is what I get:

[ empty ]
A
A
C
D
F

What I would like is this:

A
A
C
D
F
[ empty ]

Is there any way to achieve this in a single MySQL query? Using DESC  
in this case doesn't work, because while it puts the empty row in the  
last place, it does the rest as well. I could also do 2 queries where  
it calls it once in order WHERE  !='', and then do another query to  
get the empty ones, but that seems a bit cumbersome.

-- 
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326




-- 
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux