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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with query to combine independent tables 1

Status
Not open for further replies.

safaryan

Technical User
Aug 17, 2006
8
US
this may sound a really dumb question since I'm new to Access and relational databases - I have 3 independent tables: tblBudget_CA, tblBudget_WA, tblBudget_OR (one for each State) with identical fields each: Market, Brand, Account, Amount. I need a query that combines all three in one table with the same fields: Market, Brand, Account, Amount. I have tried a make-Table query and it doesn't work since I get duplicate fields (3 Market fields, 3 Brand fields, etc). The key is to keep the tables independent. Any help is greatly appreciated.

Max
 
Code:
Select * INTO NewTable

From
(
Select 'CA' As State, X.* From tblBudget_CA X
UNION ALL
Select 'WA', X.* From tblBudget_WA X
UNION ALL
Select 'OR', X.* From tblBudget_OR X
)
 
Golom
I tried it and it worked, you are the best - thanks! :) the only problem is I get weird field names - should I replace the Xs with something else?

Max
 
You should be getting "State" as the first field name followed by the field names as they appear in tblBudget_CA. Is that not what you are seeing?

Can you provide more detail about how the field names are "weird"?
 
I've got "X7YZ_____1_State" as my State field. I guess I had to replace the Xs in your code with the field names - correct?
 
I'm not sure but maybe "State" is a reserved word. Try
Code:
Select * INTO NewTable

From
(
Select 'CA' As [red][[/red]State[red]][/red], X.* From tblBudget_CA X
UNION ALL
Select 'WA', X.* From tblBudget_WA X
UNION ALL
Select 'OR', X.* From tblBudget_OR X
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top