动态地如何将数据从多个表插入单个表

时间:2018-08-13 12:47:41

标签: tsql

表1:

Groupname   View
member      table a
non member  table b

表a:

id  key
1   A
2   B
3   C

表B:

ID  KEY
1   M
2   L
3   H
4   G
5   F

最终输出:

GROUPNAME   KEY
member      A
member      B
member      C
non member  M
non member  L
non member  H
non member  G
non member  F

1 个答案:

答案 0 :(得分:0)

Select 'member' as GROUPNAME, KEY as KEY from [table a]
UNION
Select 'non member' as GROUPNAME, KEY as KEY from [table b]