MS-Access: Merge two tables “below” each other

女生的网名这么多〃 提交于 2019-12-07 06:54:55

问题


I have two tables in my Access-database. They look something like this:

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     |
+--------------+----------+----------+----------+

I need a query that gives me 1 table with the data from table1 added to the data from 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     |
+--------------+----------+----------+----------+

The names "Column1", "Column2" and "Column3" are the same in both tables


回答1:


SELECT *
FROM  Table1

UNION

SELECT *
FROM table2;



回答2:


The question asks for non-distinct values while the current answers provide distinct values. The method below provides non-distinct values such that

SELECT *
FROM  Table1

UNION ALL

SELECT *
FROM table2;

which is often more efficient than the union method, particularly with large data sets (not having to compute the distinct).




回答3:


If your goal is to append the second table to the first one, it can be achieved this way

INSERT INTO TABLE1 SELECT * FROM TABLE2;

The caveat with these other queries is that yes, they do the job, but create a third table with the joined data.



来源:https://stackoverflow.com/questions/17923643/ms-access-merge-two-tables-below-each-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!