开发者

MySQL order question

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 the开发者_StackOverflow中文版m by middle name?


You could do something like this:

    SELECT fields 
      FROM table 
     WHERE condition 
  ORDER BY first_name, last_name, middle_name ASC


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜