Solved

Discrepency in values returned by queries

Posted on 2015-02-02
5
61 Views
Last Modified: 2015-02-18
Hello,

I have three queries that I am using to populate a spreadsheet.  The number of records returned by query 1 should equal the sum of the records from query 2 and query 3.  However, query 1 is returning 2799 records while the sum of the records returned by queries 2 and 3 is 2900 records.  There is a difference of 101 records.  I've been trying to figure out why I'm getting this discrepancy.

Query 1
SELECT DISTINCT NE_StockInAllWarehouses.Item_Code
FROM ((NE_StockInAllWarehouses LEFT JOIN dbo_query_Item_Master ON NE_StockInAllWarehouses.Item_Code=dbo_query_Item_Master.Item_Code) LEFT JOIN dbo_query_Item_Group ON (dbo_query_Item_Master.Item_Group=dbo_query_Item_Group.Item_Group) AND (dbo_query_Item_Master.Site_Code=dbo_query_Item_Group.Site_Code)) LEFT JOIN Planner_Location ON dbo_query_Item_Master.Planner_Code=Planner_Location.Planner_Code
WHERE (Planner_Location.Location="LTN" Or Planner_Location.Location="QRO") AND (dbo_query_Item_Master.Signal_Code="E01" Or dbo_query_Item_Master.Signal_Code="E02" Or dbo_query_Item_Master.Signal_Code="E03")
GROUP BY NE_StockInAllWarehouses.Item_Code;

Open in new window


Query 2
SELECT DISTINCT NE_StockInAllWarehouses.Item_Code
FROM ((NE_StockInAllWarehouses LEFT JOIN dbo_query_Item_Master ON NE_StockInAllWarehouses.Item_Code = dbo_query_Item_Master.Item_Code) LEFT JOIN dbo_query_Item_Group ON (dbo_query_Item_Master.Item_Group = dbo_query_Item_Group.Item_Group) AND (dbo_query_Item_Master.Site_Code = dbo_query_Item_Group.Site_Code)) LEFT JOIN Planner_Location ON dbo_query_Item_Master.Planner_Code = Planner_Location.Planner_Code
WHERE Planner_Location.Location="LTN" AND (dbo_query_Item_Master.Signal_Code="E01" Or dbo_query_Item_Master.Signal_Code="E02" Or dbo_query_Item_Master.Signal_Code="E03")
GROUP BY NE_StockInAllWarehouses.Item_Code;

Open in new window

Query 3
SELECT DISTINCT NE_StockInAllWarehouses.Item_Code
FROM ((NE_StockInAllWarehouses LEFT JOIN dbo_query_Item_Master ON NE_StockInAllWarehouses.Item_Code=dbo_query_Item_Master.Item_Code) LEFT JOIN dbo_query_Item_Group ON (dbo_query_Item_Master.Item_Group=dbo_query_Item_Group.Item_Group) AND (dbo_query_Item_Master.Site_Code=dbo_query_Item_Group.Site_Code)) LEFT JOIN Planner_Location ON dbo_query_Item_Master.Planner_Code=Planner_Location.Planner_Code
WHERE Planner_Location.Location="QRO" AND (dbo_query_Item_Master.Signal_Code="E01" Or dbo_query_Item_Master.Signal_Code="E02" Or dbo_query_Item_Master.Signal_Code="E03")
GROUP BY NE_StockInAllWarehouses.Item_Code;

Open in new window

0
Comment
Question by:chtullu135
  • 3
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40584397
There is likely overlap between the [Item_Code] values returned by query2 and query3.  Save those two queries and then run this query:

SELECT Q2.[Item_Code]
FROM query2 as Q2 INNER JOIN query3 as Q3
ON Q2.Item_Code = Q3.Item_Code

This will identify the [Item_Code] values that are in common between the two queries.
0
 

Author Comment

by:chtullu135
ID: 40584455
Thanks Dale.  I'll give it a shot.
0
 

Author Comment

by:chtullu135
ID: 40586599
Hello Dale,

I found out the problem and it was an overlap problem.  I added some additional criteria, and that resolved the issue.

Juan.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40586729
glad I could help.
0
 

Author Closing Comment

by:chtullu135
ID: 40618122
Thanks for your help.  I thought I had already submitted my acceptance of your solution.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question