Combining Tables

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

I have 12 tables with 12 months of data. The fields names in each table are
exactly the same (incident number, date, etc.), with the data in each table
representing a month of data. How do I combine these 12 tables into one
table?
 
do a UNION query:

select * from tbl1
UNION
select * from tbl2
....
UNION
select * from tb12

Note: Union queries automatically removes the dups from all the tables.


Ben
 
Why do you need to combine into 1 table ?
Create a union query which selects the data from the 12 tables.
SELECT * FROM [TableNameforMonth1];
UNION ALL SELECT * FROM [TableNameforMonth2];
UNION ALL SELECT * FROM [TableNameforMonth3];
etc.
 
You might want it like this --
SELECT *, 1 AS Month_All FROM [TableNameforMonth1]
UNION ALL SELECT *, 2 AS Month_All FROM [TableNameforMonth2]
UNION ALL SELECT *, 3 AS Month_All FROM [TableNameforMonth3]
......
UNION ALL SELECT *, 12 AS Month_All FROM [TableNameforMonth12];

--
KARL DEWEY
Build a little - Test a little


RonaldoOneNil said:
Why do you need to combine into 1 table ?
Create a union query which selects the data from the 12 tables.
SELECT * FROM [TableNameforMonth1];
UNION ALL SELECT * FROM [TableNameforMonth2];
UNION ALL SELECT * FROM [TableNameforMonth3];
etc.

Adam said:
I have 12 tables with 12 months of data. The fields names in each table are
exactly the same (incident number, date, etc.), with the data in each table
representing a month of data. How do I combine these 12 tables into one
table?
 
Back
Top