如何在表格中添加列?

时间:2010-09-17 15:53:12

标签: sql mysql

我想添加两个表。但是我应该如何区分哪个条目来自哪个表?

表1

col1 
-----
a
b
c

表2

1
2
3

结果应为:

col1 tablename
----------------
a     table1
b      "
c      "
d     table2
e      "
f      "

1 个答案:

答案 0 :(得分:2)

Select Table1.Col1, "Table1" as 'TableName'
From dbo.Table1

Union all

Select Table2.Col1, "Table2" as 'TableName'
From dbo.Table2