Dave
Dave

Reputation: 131

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 sat row21, row22, row23

Can anyone provide me with the SQL to create a query that returns

row11
row12
row21
row22
row23

Note: I dont want to create a new table just return the data.

Upvotes: 13

Views: 92679

Answers (4)

user3103059
user3103059

Reputation:

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

INSERT INTO TABLE1 SELECT * FROM TABLE2;

Upvotes: 1

OMG Ponies
OMG Ponies

Reputation: 332581

Use UNION ALL, based on the example data:

SELECT * FROM TABLE1
UNION ALL
SELECT * FROM TABLE2

UNION removes duplicates - if both tables each had a row whose values were "rowx, 1", the query will return one row, not two. This also makes UNION slower than UNION ALL, because UNION ALL does not remove duplicates. Know your data, and use appropriately.

Upvotes: 35

Myles J
Myles J

Reputation: 2880

Why not use a UNION?

SELECT Col1,Col2,Col3 FROM TABLE1

UNION

SELECT Col1,Col2,Col3 FROM TABLE2

Are the columns on the two tables identical?

Upvotes: 1

Ned Batchelder
Ned Batchelder

Reputation: 375594

select * from table1 union select * from table2

Upvotes: 8

Related Questions