Union Query

shijuantony2002

Registered User.
Local time
Tomorrow, 01:59
Joined
Feb 23, 2009
Messages
35
I need to combine 5 set of queries into one. I know this should work with UNION ALL in SQL, but don't know how to place it.

For e.g. the query names are query1, query2, query3, query4 and query5. Each of these queries have same set of field name, A, B & C and output may also goes similar. But i want the UNION ALL query to combine all the data from query ignoring the duplicates.


will it work?
 
Try some thing like

Select Query1.A, Query1.B, Query1.C from Query1
UNION ALL
Select Query2.A, Query2.B, Query2.C from Query2
Union ALL
Select Query3.A, Query3.B, Query3.C from Query3

etc

Hope this helps
 
Thanks Rabbie, it worked perfectly.

Can i also change the heading of one field to what i require to be named as. For e.g. i want the field C output to be named as "DON".


Also i want the SQL to be grouped by say field B.
 
That shouldn't be a problem

try

Select Query1.A, Query1.B, Query1.C as DON from Query1
UNION ALL
Select Query2.A, Query2.B, Query2.C as DON from Query2
Union ALL
Select Query3.A, Query3.B, Query3.C as DON from Query3

etc

I don't think you can use GROUPING unless you are using aggrgate functions in your query.
 

Users who are viewing this thread

Back
Top Bottom