开发者

MySQL order question

开发者 https://www.devze.com 2023-01-11 00:19 出处:网络
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中文

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

精彩评论

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