OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
Re: How to change where NULL values sort?

From: Martijn Engler (martijncrystal-labs.nl)
Date: Sat Apr 18 2009 - 17:58:14 CDT


They'll normally sort at the top, unless you use ORDER BY DESC.
Anyway, fixing that is easy:
SELECT col1, col1 IS NULL AS isnull
FROM tbl1
ORDER BY isnull DESC, col1 ASC

That should give you the results ordered by col1, with the null-values
at the top.

- Martijn

On Sat, Apr 18, 2009 at 19:54, David M. Karr <davidmichaelkarrgmail.com> wrote:
> I think normally NULL values will sort at the end, correct?  I believe
> there's a way to make NULL values sort at the beginning, but I can't
> remember how to do it.  I just searched a couple of MySQL resources, but I
> couldn't find it.
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
>  http://lists.mysql.com/mysql?unsub=martijncrystal-labs.nl
>
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql