List:General Discussion« Previous MessageNext Message »
From:Martijn Engler Date:April 18 2009 10:58pm
Subject:Re: How to change where NULL values sort?
View as plain text  
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 <davidmichaelkarr@stripped> 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=1
>
>
Thread
How to change where NULL values sort?David M. Karr18 Apr
  • Re: How to change where NULL values sort?Martijn Engler19 Apr