Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining Data from 3 tables with SQL 2

Status
Not open for further replies.

SlakeB

MIS
Jun 15, 2005
40
US
I have three tables. Each of these tables have the same structure (same fields). I want to create a new table with the same structure, and I want to put all the records from the other 3 tables into it (kind of like a master table).

Does anyone know how to do this with SQL? The SQL doesn't need to create the new table, just populate it with the records from the existing 3.
 
try using UNION ALL...something like this...

SELECT field1, field2 FROM Table1
UNION ALL
SELECT field1, field2 FROM Table2
UNION ALL
SELECT field1, field2 FROM Table3


-DNG
 
Something like this ?
INSERT INTO yourNewTable SELECT * FROM (
SELECT * FROM yourTable1
UNION ALL SELECT * FROM yourTable2
UNION ALL SELECT * FROM yourTable3
) AS U;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks!

this worked:
INSERT INTO yourNewTable SELECT * FROM (
SELECT * FROM yourTable1
UNION ALL SELECT * FROM yourTable2
UNION ALL SELECT * FROM yourTable3
);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top