0

I have 2 tables with identical columns. Is there a way I can append them together. For example if my tables are:

Table 1:

ID  Age
 1   21
 2   26
 3   19
 4   40

Table 2:

ID  Age
 6   29
 8   40
10   35

I'd like the desired output to be:

ID  Age
 1   21
 2   26
 3   19
 4   40
 6   29
 8   40
10   35

Is there a way I can append these 2 tables. Being new to SQL I tried using insert but couldn't do much about it.

Would be great if some one can help out

ollie
  • 1,009
  • 1
  • 8
  • 11
user6016731
  • 382
  • 5
  • 18

2 Answers2

1

You can use a UNION ALL query:

SELECT ID, Age
FROM table1
UNION ALL
SELECT ID, Age
FROM table2

This will return all rows from each table in a single result. Here is a demo.

Community
  • 1
  • 1
ollie
  • 1,009
  • 1
  • 8
  • 11
0

Use Union rather Union All if you want unique values based on two tables.

https://stackoverflow.com/a/49928/2745294

SELECT ID, Age
FROM table1
UNION
SELECT ID, Age
FROM table2
Community
  • 1
  • 1
Sushil Mate
  • 583
  • 6
  • 14