MS-Access: Merge two tables "below" each other
Asked Answered
D

3

5

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

Disarray answered 29/7, 2013 at 12:9 Comment(1)
Neither answer here guarantees any order to the output rows.Cornaceous
M
7
SELECT *
FROM  Table1

UNION

SELECT *
FROM table2;
Makeup answered 29/7, 2013 at 12:10 Comment(0)
U
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).

Uniformity answered 18/4, 2017 at 14:25 Comment(0)
P
0

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.

Pardoes answered 3/10, 2019 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.