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

Union query 3 files with different fields

Status
Not open for further replies.

caddiva1

MIS
Nov 2, 2009
3
0
0
US
I have 3 files I want to combine:
Table x with Field 1, field 2 and field 3
Tab;e y with Field 1, field 4 and field 5
table z with field 2, field 6 and field 7

how do I create a union query to get them all together:
Select Field 1, field 2, field 3....field 7 from x

How do I pad the tables with no fields so I don't get a parameter pop up.
 
Select field1,field2,field3
From Table1
union
Select field4,field5,field6
From Table2
union
Select field2,field7,null
From Table3
 
That's not exactly what I meant. That would put all the data into the 3 fields. What I want returned is:

Field 1, field 2, field 3, field 4, field 5, field6, field 7

the only common field is Field 1 and the results might look like this:

group A, 25, $100, 0, 0, 0, 0
Group B, 0, 0, 20, $75, 10, $40
 

Try:
Code:
Select x.Field1, x.Field2, x.Field3, 
   y.Field4, y.Field5,
   z.Field6, z.Field7
From TableX x, TableY y, TableZ z
Where TableX.Field1 = TableY.Field1
And TableY.Field[red]???[/red] = TableZ.Field[red]???[/red]

Have fun.

---- Andy
 
Code:
Select field1,field2,field3, 
       NULL As field4, NULL As field5, 
       NULL As field6, NULL As field7
From Tablex

union

Select field1, NULL, NULL, field4, field5, NULL, NULL
From Tabley

union

Select NULL, field2, NULL, NULL, NULL, NULL, field7
From Tablez
 
Thanks!!! that works and I can now get rid of my bogus table I created to include all of the fields...once I realized I could use null
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top