[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Discrepency in values returned by queries

Posted on 2015-02-02
5
Medium Priority
?
68 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 earned 2000 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
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

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…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

650 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