tags:

views:

35

answers:

2

Is there a way I can order a group of users by first name and if a user didn't enter a first name order that user by last name or if they didn't enter a last name order them by middle name?

+3  A: 

You could do something like this:

    SELECT fields 
      FROM table 
     WHERE condition 
  ORDER BY first_name, last_name, middle_name ASC
NullUserException
+1  A: 

I'm assuming 'didn't enter' equates to a null field.

    SELECT fields  
      FROM table  
     WHERE condition  
  ORDER BY COALESCE(first_name, last_name, middle_name)
Dave Barker
`COALESCE(first_name, last_name, middle_name)` ;)
OMG Ponies
Oops, forgot about that. Updated answer.
Dave Barker
@Dave Barker are you giving 2 examples or just one?
order
Removed additional isNull answer as COALESCE is the better option
Dave Barker