SQL Server: merging multiple colums into 1 column
Hey there I have 2 tables with each multiple columns and i want to merge them in a view with 1 column.
table1
data1 data2 data 3
lala blabla aaa
table2
data1 data2 data 3
qqq wwww eee
into开发者_如何学C 1 view with 1 column
merged view
data1
lala
blabla
aaa
qqqq
wwww
eee
I'm using SQL Server, anyone has an idea :)
WITH cte(data1, data2, data3) As
(
SELECT data1, data2, data3 FROM table1
UNION ALL
SELECT data1, data2, data3 FROM table2
)
SELECT data
FROM cte
UNPIVOT (data FOR d IN
(data1, data2, data3)
)AS unpvt
select data1 from table1
union all
select data2 from table1
union all
...
select data3 from table2
精彩评论