私はこれを試した:
SELECT first_name,last_name,company_name FROM users ORDER BY last_name, company_name ASC
I have a users
table like this:
+------------------+--------------------+--------------------+
| first_name | last_name | company_name |
+------------------+--------------------+--------------------+
| Alfa | Alfa | Bravo |
+------------------+--------------------+--------------------+
| Echo | Echo | Alfa |
+------------------+--------------------+--------------------+
| Delta | Delta | |
+------------------+--------------------+--------------------+
| | | Charlie |
+------------------+--------------------+--------------------+
現時点での行の順序は次のとおりです。
, ,Charlie
Alfa, Alfa, Bravo
Delta, Delta,
Echo, Echo, Alfa
What I would like to achieve, is to order rows primarily by last_name but if it's not available (empty), order by company_name but in a way that it still compares this company_name-column with the last_name-columns... Sorry for possible inaccurate explanation. Here is the order I'd like to achieve:
Alfa, Alfa, Bravo
, ,Charlie
Delta, Delta,
Echo, Echo, Alfa
EDIT: Is this possible via a single MySQL query?