Sorting a MySQL query with ORDER BY or with PHP sort functions

前端 未结 5 1150
深忆病人
深忆病人 2020-12-21 16:27

I have a query that I want to sort alphabetically, but the trick is that I want the sorting to treat two columns equally. For instance, if the first row of first_col<

5条回答
  •  难免孤独
    2020-12-21 17:06

    As they say above, UNION ALL is your friend, and, of course, if you have only one table, you can always do this:

    (SELECT field1 AS name FROM TABLE1) 
    UNION ALL 
    (SELECT field2 AS name FROM TABLE1) 
    ORDER BY name DESC
    

    So, you are asking for two diferent rows in the same table, and ordering it as it was one.

提交回复
热议问题