How to order by column with non-null values first in sql

Posted by devlife on Stack Overflow See other posts from Stack Overflow or by devlife
Published on 2010-05-11T00:35:16Z Indexed on 2010/05/11 0:44 UTC
Read the original article Hit count: 294

Filed under:
|

I need to write a sql statement to select all users ordered by lastname, firstname. This is the part I know how to do :) What I don't know how to do is to order by non-null values first. Right now I get this:

null, null
null, null
p1Last, p1First
p2Last, p2First

etc

I need to get:

p1Last, p1First
p2Last, p2First
null, null
null, null

Any thoughts?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server