Click to See Complete Forum and Search --> : Combine two tables into 1


mparker1113
01-22-2007, 01:31 AM
Hi,

I have two temp tables that i create. each has the same exact fields. I would like to do a select which combines these seamlessly into one table.

Is that possible?

I tried select tbl1.*, tbl2.* from table as tbl1, table2 as tbl2, but it just appended the results from table 2 to the end of the tbl 1 results.

I would like for them to exist in one table under the same field names.

(much thanks for input)

NightShift58
01-22-2007, 02:04 AM
This?INSERT INTO tbl1 SELECT * FROM tbl2You want to be careful with duplicate keys, if any. You can also influence the insertion order by using ORDER BY.

chazzy
01-22-2007, 08:20 PM
you probably want a union, if they have the same columns


SELECT (columns) from table1
UNION
SELECT (columns) from table2

NightShift58
01-22-2007, 11:18 PM
I would like for them to exist in one table under the same field names.SELECT (columns) from table1
UNION
SELECT (columns) from table2In order to create a third table, we would need to change this to at least;CREATE TABLE table3
SELECT * from table1
UNION
SELECT * from table2)

chazzy
01-23-2007, 07:10 AM
The only requirements are I would like to do a select which combines these seamlessly into one table. that i looked at. Both solutions are equally valid. I'm not 100% clear that he wants to create a third table, as his post is somewhat vague.