MS-Access:合并两个表"以下"彼此

时间:2013-07-29 12:09:26

标签: sql ms-access ms-access-2007

我的Access数据库中有两个表。他们看起来像这样:

Table1
+--------------+----------+----------+----------+
| Kabelnummer  |  Column1 |  Column2 |  Column3 |         
+--------------+----------+----------+----------+
| 1            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 2            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 3            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 4            |    x     |    x     |    x     |
+--------------+----------+----------+----------+

table2
+--------------+----------+----------+----------+
| Kabelnummer  |  Column1 |  Column2 |  Column3 |        
+--------------+----------+----------+----------+
| 1            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 2            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 3            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 4            |    x     |    x     |    x     |
+--------------+----------+----------+----------+

我需要一个查询,它为我提供了一个表,其中table1中的数据被添加到table2中的数据中:

TableTotal
+--------------+----------+----------+----------+
| Kabelnummer  |  Column1 |  Column2 |  Column3 | 
+--------------+----------+----------+----------+
| 1            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 2            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 3            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 4            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 1            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 2            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 3            |    x     |    x     |    x     |
+--------------+----------+----------+----------+
| 4            |    x     |    x     |    x     |
+--------------+----------+----------+----------+

两个表中的名称“Column1”,“Column2”和“Column3”相同

3 个答案:

答案 0 :(得分:7)

SELECT *
FROM  Table1

UNION

SELECT *
FROM table2;

答案 1 :(得分:0)

当前答案提供不同的值时,问题会询问非独特的值。下面的方法提供了非明确的值,例如

SELECT *
FROM  Table1

UNION ALL

SELECT *
FROM table2;

通常比union方法更有效,特别是对于大型数据集(不必计算不同的数据集)。

答案 2 :(得分:0)

如果您的目标是将第二张表追加到第一张表,则可以通过这种方式实现

INSERT INTO TABLE1 SELECT * FROM TABLE2;

这些其他查询的警告是,是的,它们确实可以完成工作,但是使用联接的数据创建 第三张表