473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Union Query Question missing records......

kcdoell
230 100+
Hello:

I am trying to create a union query but do not have a lot of experience. Basically I have the below tables:

The Tables:

Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblPrior
  2.  
  3. CreditRegIDFK;    Number;    Foreign Key for the Credit Region ID
  4. Field    Type    IndexInfo
  5. YearID;    Number;    Year
  6. MonthID;    Number;    Foreign Key for the Month ID
  7. GWP;    Number;    Gross Premium
  8. NWP;    Number;    Gross Premium
  9. ProductIDFK;    Number;    Foreign Key for the Product ID
  10. ProductName;    Text;    Product Name
  11.  
Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblbudget        
  2.  
  3. CreditRegIDFK;    Number;    Foreign Key for the Credit Region ID
  4. Field    Type    IndexInfo
  5. YearID;    Number;    Year
  6. MonthID;    Number;    Foreign Key for the Month ID
  7. GWP;    Number;    Gross Premium
  8. NWP;    Number;    Gross Premium
  9. ProductIDFK;    Number;    Foreign Key for the Product ID
  10. ProductName;    Text;    Product Name
  11.  
Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblCreditRegion        
  2.  
  3. Field    Type    IndexInfo
  4. CreditRegID;    AutoNumber;    The Credit ID
  5. CreditRegionName;    Text;    Product Name
  6.  
Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblproduct        
  2.  
  3. Field    Type    IndexInfo
  4. ProductID;    AutoNumber;    The Product ID
  5. ProductName;    Text;    Product Name
  6. ProductType; Text;    Product  Type
  7.  
tblbudget has 7,021 records in it and tblPrioir has 3,064. I am trying to create a union query that will give me a total of 10,085. So far I wrote the following union query:

Query Name = UqryProductTypeStatic:

Expand|Select|Wrap|Line Numbers
  1.  SELECT 
  2. [DivisionIDFK], [WrkRegIDFK], [CreditRegionName], [ProductType], 0 AS [GWP_PRI], 0 AS [NWP_PRI], [GWP] AS [GWP_BUD], [NWP] AS [NWP_BUD], [MonthID], [YearID], 0 AS [GWP_STAT], 0 AS [NWP_STAT], 0 AS [FWeek]
  3. FROM tblProduct 
  4. INNER JOIN (tblCreditRegion INNER JOIN tblbudget 
  5. ON tblCreditRegion.CreditRegID = tblbudget.CreditRegIDFK) 
  6. ON tblProduct.ProductID = tblbudget.ProductIDFK
  7. UNION SELECT
  8. [DivisionIDFK], [WrkRegIDFK], [CreditRegionName], [ProductType], [GWP] AS [GWP_PRI], [NWP] AS [NWP_PRI], 0 AS [GWP_BUD], 0 AS [NWP_BUD], [MonthID], [YearID], 0 AS [GWP_STAT], 0 AS [NWP_STAT], 0 AS [FWeek]
  9. FROM tblProduct 
  10. INNER JOIN (tblCreditRegion INNER JOIN tblPrior 
  11. ON tblCreditRegion.CreditRegID = tblPrior.CreditRegIDFK) 
  12. ON tblProduct.ProductID = tblPrior.ProductIDFK;
  13.  
but my result when I run it is only 7,276. I am not hitting any error when I run it so I am thinking that I must be missing something.

Any ideas or advice would be helpful? P.S. I did run them separately and I get 7,021 and 3,064 so I thought all that would be needed was the UNION SELECT expression....

Thanks,

Keith.
May 15 '08 #1
2 4916
puppydogbuddy
1,923 Expert 1GB
Hello:

I am trying to create a union query but do not have a lot of experience. Basically I have the below tables:

The Tables:

Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblPrior        
  2.  
  3. CreditRegIDFK;    Number;    Foreign Key for the Credit Region ID
  4. Field    Type    IndexInfo
  5. YearID;    Number;    Year
  6. MonthID;    Number;    Foreign Key for the Month ID
  7. GWP;    Number;    Gross Premium
  8. NWP;    Number;    Gross Premium
  9. ProductIDFK;    Number;    Foreign Key for the Product ID
  10. ProductName;    Text;    Product Name
  11.  
Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblbudget        
  2.  
  3. CreditRegIDFK;    Number;    Foreign Key for the Credit Region ID
  4. Field    Type    IndexInfo
  5. YearID;    Number;    Year
  6. MonthID;    Number;    Foreign Key for the Month ID
  7. GWP;    Number;    Gross Premium
  8. NWP;    Number;    Gross Premium
  9. ProductIDFK;    Number;    Foreign Key for the Product ID
  10. ProductName;    Text;    Product Name
  11.  
Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblCreditRegion        
  2.  
  3. Field    Type    IndexInfo
  4. CreditRegID;    AutoNumber;    The Credit ID
  5. CreditRegionName;    Text;    Product Name
  6.  
Expand|Select|Wrap|Line Numbers
  1. Table Name =  tblproduct        
  2.  
  3. Field    Type    IndexInfo
  4. ProductID;    AutoNumber;    The Product ID
  5. ProductName;    Text;    Product Name
  6. ProductType; Text;    Product  Type
  7.  
tblbudget has 7,021 records in it and tblPrioir has 3,064. I am trying to create a union query that will give me a total of 10,085. So far I wrote the following union query:

Query Name = UqryProductTypeStatic:

Expand|Select|Wrap|Line Numbers
  1.  SELECT 
  2. [DivisionIDFK], [WrkRegIDFK], [CreditRegionName], [ProductType], 0 AS [GWP_PRI], 0 AS [NWP_PRI], [GWP] AS [GWP_BUD], [NWP] AS [NWP_BUD], [MonthID], [YearID], 0 AS [GWP_STAT], 0 AS [NWP_STAT], 0 AS [FWeek]
  3. FROM tblProduct 
  4. INNER JOIN (tblCreditRegion INNER JOIN tblbudget 
  5. ON tblCreditRegion.CreditRegID = tblbudget.CreditRegIDFK) 
  6. ON tblProduct.ProductID = tblbudget.ProductIDFK
  7. UNION SELECT
  8. [DivisionIDFK], [WrkRegIDFK], [CreditRegionName], [ProductType], [GWP] AS [GWP_PRI], [NWP] AS [NWP_PRI], 0 AS [GWP_BUD], 0 AS [NWP_BUD], [MonthID], [YearID], 0 AS [GWP_STAT], 0 AS [NWP_STAT], 0 AS [FWeek]
  9. FROM tblProduct 
  10. INNER JOIN (tblCreditRegion INNER JOIN tblPrior 
  11. ON tblCreditRegion.CreditRegID = tblPrior.CreditRegIDFK) 
  12. ON tblProduct.ProductID = tblPrior.ProductIDFK;
  13.  
but my result when I run it is only 7,276. I am not hitting any error when I run it so I am thinking that I must be missing something.

Any ideas or advice would be helpful? P.S. I did run them separately and I get 7,021 and 3,064 so I thought all that would be needed was the UNION SELECT expression....

Thanks,

Keith.
Keith,
Try changing line 7 To>>>>>> Union ALL Select
May 15 '08 #2
kcdoell
230 100+
Keith,
Try changing line 7 To>>>>>> Union ALL Select
That was it! Thanks a million

Keith.
May 15 '08 #3

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

Similar topics

3
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID ...
3
by: Dalan | last post by:
From reading Access 97 help text, it seems that to do what I need to do will require a Union Query. As this would be my first, I think I might require a little guidance. I have two tables with...
2
by: M Stery | last post by:
Have two base queries used for mailing labels with id,name,address,city,state,zip that are combined via a union query. One base query uses home address; the other base query uses biz address. I...
2
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code ...
5
by: BillCo | last post by:
I'm having a problem with a union query, two simple queries joined with a union statement. It's created in code based on parameters. Users were noticing some inconsistant data and when I analysed...
2
by: Thomas | last post by:
Hi All. I think that if I explain the database layout first it may be easier to ask my question. Table Name Field Name Test TestCode Description SpecimenRequirements FeeSchedule TestCode...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
1
by: cashotte | last post by:
Hi, Is there a way to have a union query (2 tables) in an other query then join a third table having the ability to edit records in the third table? Thanks, Stephane
5
by: tasawer | last post by:
I need some assistance with SQL query. I will be grateful if you can provide help please. I have a database that records details of a road traffic accident and name of driver. sub-form records...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.