Solved

Discrepency in values returned by queries

Posted on 2015-02-02
5
58 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now