开发者

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.


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.


select * from table1 union select * from table2


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?


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

INSERT INTO TABLE1 SELECT * FROM TABLE2;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜