Jump to content

Mysql Order By Question


murfitUK
 Share

Recommended Posts

I've got a table with id, firstname, lastname and a reference code. Anonymous clients have an id and a code, but the firstname and lastname fields are left blank.My query to produce a list of name is "SELECT * FROM `clients` ORDER BY `lastname`,`firstname`;" and then the php prints it all out.This worked well to start with but as the number of anonymous clients has grown all the blank clients are listed first followed by those with proper names listed A-Z. As a way round this I have changed the ORDER BY to do lastname DESC, so now I get Z-A clients followed by the blanks - but it just doesn't look right.What I'd like to do is have the proper A-Z followed by the blanks. Can this be done in a single query? Or do I have to do one query with `lastname` not blank, stick the results into a php array, then do a second query with the blanks and add those to the array?What's the easiest way?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...