开发者

SQL Server: merging multiple colums into 1 column

开发者 https://www.devze.com 2023-02-10 04:34 出处:网络
Hey there I have 2 tables with each multiple columnsand i want to merge them in a view with 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号