Solved

Discrepency in values returned by queries

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

732 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