我想添加两个表。但是我应该如何区分哪个条目来自哪个表?
col1
-----
a
b
c
1
2
3
结果应为:
col1 tablename
----------------
a table1
b "
c "
d table2
e "
f "
答案 0 :(得分:2)
Select Table1.Col1, "Table1" as 'TableName'
From dbo.Table1
Union all
Select Table2.Col1, "Table2" as 'TableName'
From dbo.Table2