kpwhitte
asked on
Contatinating 2 tables
How do I concatenate two tables, identical in structure, into one table?
thanks.
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Create a temp taable
Union the results from two tables and insert in temp table
Thanks,
Union the results from two tables and insert in temp table
Thanks,
i don't (and i don't think the others do either) understand what you mean by concatenate two tables together....,
do you want the whole set? UNION ALL
do you want the unique set? UNION
do you want to Update the rows with the same key using some business logic?
which version of SQL Server are you using?
please explain in more detail what you are attempting to achieve and the key structure of the tables and the data (unique/non unique ...) dynamics involved..
do you want the whole set? UNION ALL
do you want the unique set? UNION
do you want to Update the rows with the same key using some business logic?
which version of SQL Server are you using?
please explain in more detail what you are attempting to achieve and the key structure of the tables and the data (unique/non unique ...) dynamics involved..
Hi,
Please do specify clearly what excatly is your requirement
1. Do you wan your data to be combined and put in it a new table?
insert into <New Table> select * from table1 union all select * from table2 -- replace the tagged portion with your new table name.
2. Do you wish to insert all the records in Table2 into Table1?
Insert into Table1 select * from Table2 -- If duplicate records are there in both the tables and you have primary key defined, then this will give you error.
3. Do you wish to create a third table and then insert all the values from Table1 and Table2 go with this.
Create Table3 with the same structure as Table1 or Table2
Insert into Table3 select * from Table1 union all select * from Table2
Please do specify clearly what excatly is your requirement
1. Do you wan your data to be combined and put in it a new table?
insert into <New Table> select * from table1 union all select * from table2 -- replace the tagged portion with your new table name.
2. Do you wish to insert all the records in Table2 into Table1?
Insert into Table1 select * from Table2 -- If duplicate records are there in both the tables and you have primary key defined, then this will give you error.
3. Do you wish to create a third table and then insert all the values from Table1 and Table2 go with this.
Create Table3 with the same structure as Table1 or Table2
Insert into Table3 select * from Table1 union all select * from Table2
would do the trick initially.
but watch out for constraints on table1 which limit duplicate keys.