Jump to content

Mysql Order By Question


murfitUK

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...