我有一个看起来像这样的表:
+------+------+------+
| Col1 | Col2 | Col3 |
+------+------+------+
| 1 | 2 | 3 |
| 2 | 3 | 4 |
| 3 | 4 | 5 |
+------+------+------+
我想写一个查询来得到这个:
+------+
| Col1 |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+------+
我的问题是:是否可以在不使用union
的情况下将所有列合并为一个?
答案 0 :(得分:0)
是的,是的。但这并不优雅:
select distinct (case n when 1 then col1 when 2 then col2 when 3 then col3) as col
from t cross join
(select (@rn := @rn + 1) as n
from t cross join
(select @rn := 0) params
limit 3
) n;