sort NULL last

I have a mysql query, "SELECT * FROM task ORDER BY duedate ASC", where
"duedate" is a unix_timestamp and can be NULL. I want any NULL results
to be at the end of the list, how might I do this? Thanks.
mark [ Fr, 27 Oktober 2006 06:17 ] [ ID #1515621 ]

Re: sort NULL last

Mark wrote:
> I have a mysql query, "SELECT * FROM task ORDER BY duedate ASC", where
> "duedate" is a unix_timestamp and can be NULL. I want any NULL results
> to be at the end of the list, how might I do this? Thanks.

Have a look at the bottom of this post:

http://groups.google.com/group/alt.php.sql/browse_thread/thr ead/ad3bc576fb0631b7/960d115e698ca173?lnk=st&q=%22AS+ISNULL% 22&rnum=3#960d115e698ca173
zac.carey [ Fr, 27 Oktober 2006 11:30 ] [ ID #1515622 ]

Re: sort NULL last

strawberry wrote:
> Mark wrote:
> > I have a mysql query, "SELECT * FROM task ORDER BY duedate ASC", where
> > "duedate" is a unix_timestamp and can be NULL. I want any NULL results
> > to be at the end of the list, how might I do this? Thanks.
>
> Have a look at the bottom of this post:
>
> http://groups.google.com/group/alt.php.sql/browse_thread/thr ead/ad3bc576fb0631b7/960d115e698ca173?lnk=st&q=%22AS+ISNULL% 22&rnum=3#960d115e698ca173

IF(l_name IS NULL or l_name='', 1, 0)
AS isnull
FROM students
ORDER BY isnull ASC, l_name ASC;";

what is the 1,0 for after name='' ?
mark [ Sa, 28 Oktober 2006 23:51 ] [ ID #1516617 ]

Re: sort NULL last

Mark wrote:
> strawberry wrote:
> > Mark wrote:
> > > I have a mysql query, "SELECT * FROM task ORDER BY duedate ASC", where
> > > "duedate" is a unix_timestamp and can be NULL. I want any NULL results
> > > to be at the end of the list, how might I do this? Thanks.
> >
> > Have a look at the bottom of this post:
> >
> > http://groups.google.com/group/alt.php.sql/browse_thread/thr ead/ad3bc576fb0631b7/960d115e698ca173?lnk=st&q=%22AS+ISNULL% 22&rnum=3#960d115e698ca173
>
> IF(l_name IS NULL or l_name='', 1, 0)
> AS isnull
> FROM students
> ORDER BY isnull ASC, l_name ASC;";
>
> what is the 1,0 for after name='' ?

ah.. nvm

IF(expr1,expr2,expr3)

If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns
expr2; otherwise it returns expr3. IF() returns a numeric or string
value, depending on the context in which it is used.
mark [ So, 29 Oktober 2006 00:08 ] [ ID #1516618 ]
Datenbanken » mailing.database.mysql » sort NULL last

Vorheriges Thema: Can it be done better?
Nächstes Thema: Same database name