MySQL: Get unique values across multiple columns in alphabetical order

后端 未结 2 1702
借酒劲吻你
借酒劲吻你 2021-01-13 09:58

If my table looks like this:

id | colA   | colB | colC
===========================
1  | red    | blue | yellow
2  | orange | red  | red
3  | orange | blue |          


        
2条回答
  •  别那么骄傲
    2021-01-13 10:57

    (SELECT DISTINCT colA AS color FROM table) UNION
    (SELECT DISTINCT colB AS color FROM table) UNION
    (SELECT DISTINCT colC AS color FROM table)
    ORDER BY color
    

提交回复
热议问题