在另一列值的末尾添加一个列值

时间:2018-05-02 10:13:06

标签: mysql sql

我有一张这样的表

+----------------+----------------+----------+
|    city        |      city2     |   state  |
+----------------+----------------+----------+
|     abc        |     ghe        |    NY    |
+----------------+----------------+----------+
|     def        |     jkl        |    NY    |
+----------------+----------------+----------+

并希望此结果中citycity2的值合并为一列combined

+---------------------+
|      combined       |
+---------------------+
|        abc          |
+---------------------+
|        def          |
+---------------------+
|        ghe          |
+---------------------+
|        jkl          |
+---------------------+

2 个答案:

答案 0 :(得分:2)

一种方法使用union all;

select city as combined from t
union all
select city2 from t;

如果您想要唯一值,请使用union而不是union all

答案 1 :(得分:2)

SELECT city FROM myTable
UNION
SELECT city2 FROM myTable