By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,972 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,972 IT Pros & Developers. It's quick & easy.

Needing Help Creating a Union Query

P: 72
I need to take four queries and make them into one table

This is what I get when I just do a simple select query.
Expand|Select|Wrap|Line Numbers
  1.  SELECT 
  2. Wholesale_Rank_qry_2.OMNI_Number, 
  3. Wholesale_Rank_qry_2.branch, 
  4. Wholesale_Rank_qry_2.branch_name, 
  5. Wholesale_Rank_qry_2.[Rank>], 
  6. Wholesale_Rank_qry_2.[0to5Rank], 
  7. Wholesale_Rank_qry_2.Star_Rating, 
  9. Table_Rank_qry_2.[Rank>], 
  10. Purchase_Rank_qry_2.[Rank>], 
  11. CUSB_Rank_qry_2.[Rank>]
  13. FROM CUSB_Rank_qry_2 RIGHT JOIN (Purchase_Rank_qry_2 RIGHT JOIN (Table_Rank_qry_2 RIGHT JOIN Wholesale_Rank_qry_2 ON Table_Rank_qry_2.OMNI_Number = Wholesale_Rank_qry_2.OMNI_Number) ON Purchase_Rank_qry_2.OMNI_Number = Wholesale_Rank_qry_2.OMNI_Number) ON CUSB_Rank_qry_2.OMNI_Number = Wholesale_Rank_qry_2.OMNI_Number;
I think this is what I want, but Iím receiving a error

[b]The number of columns in the two selected tables or queries of a union query do not match[/]

Expand|Select|Wrap|Line Numbers
  1. SELECT [OMNI_Number],[branch],[branch_name],[Rank>],[0to5Rank],[Star_Rating]
  2. FROM [Wholesale_Rank_qry_2]
  5. FROM [Table_Rank_qry_2];
  8. FROM [Purchase_Rank_qry_2];
This is my first time trying to put together a union query, and I have received a lot of help and training from this form, so Iím hoping someone will be about to help me with learn how to compile a union query.

Thanks for all your help and time

Jan 5 '11 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,373
When you use a union query, the columns between the different SQL statements need to match. If I select column1 and column2 from one SQL statement, then I need two and only two columns in all subsequent SQL statements. If any one SQL statement has a different number of columns, then there will be an error.
Jan 5 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.