我有一张这样的表
+----------------+----------------+----------+
| city | city2 | state |
+----------------+----------------+----------+
| abc | ghe | NY |
+----------------+----------------+----------+
| def | jkl | NY |
+----------------+----------------+----------+
并希望此结果中city
和city2
的值合并为一列combined
+---------------------+
| combined |
+---------------------+
| abc |
+---------------------+
| def |
+---------------------+
| ghe |
+---------------------+
| jkl |
+---------------------+
答案 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