SQL append table queries

I have two tables, say table1 with two rows of data say row11 and row12 and table2 with 3 rows of data, sieve row21, row22, row23

Can someone provide me with SQL to create a query that returns

row11 row12 row21 row22 row23 

Note. I do not want to create a new table, just return the data.

+8
sql
source share
4 answers

Use UNION ALL based on sample data:

 SELECT * FROM TABLE1 UNION ALL SELECT * FROM TABLE2 

UNION removes duplicates - if both tables have a row whose values ​​were "rowx, 1", the query returns one row, not two. It also makes UNION slower than UNION ALL , because UNION ALL does not remove duplicates. Know your data and use it appropriately.

+16
source share
 select * from table1 union select * from table2 
+7
source share

Why not use UNION?

SELECT Col1, Col2, Col3 FROM TABLE1

COMPOUND

SELECT Col1, Col2, Col3 FROM TABLE2

Are the columns in the two tables the same?

+1
source share

In MS Access, you can achieve the same goal with the INSERT INTO query:

 INSERT INTO TABLE1 SELECT * FROM TABLE2; 
0
source share

All Articles