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
2010-08-12 02:04:35
+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
2010-08-12 02:10:27
`COALESCE(first_name, last_name, middle_name)` ;)
OMG Ponies
2010-08-12 02:12:22
Oops, forgot about that. Updated answer.
Dave Barker
2010-08-12 02:23:30
@Dave Barker are you giving 2 examples or just one?
order
2010-08-12 02:25:33
Removed additional isNull answer as COALESCE is the better option
Dave Barker
2010-08-12 02:38:22