Solved

Discrepency in values returned by queries

Posted on 2015-02-02
5
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 48

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 48

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

726 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