Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Left Join Not returning all records required.

Posted on 2004-09-22
4
Medium Priority
?
436 Views
Last Modified: 2006-11-17
I have a query.....

If a record in the left join doesn't meet the criteria, it omits the record from the record set, instead of just returning a stock value of 0....

How can I fix this please?   Long Query below:
-----------------------------------------
SELECT Count(Stock.[Item Number]) AS sumofqty, OrderDetails.[Order Number], OrderDetails.[Sequence Number], OrderDetails.[Item Number], OrderDetails.Description1, OrderDetails.Description2, OrderDetails.[Qty Ordered], OrderDetails.[Qty To Ship], OrderDetails.[Qty Shipped], OrderDetails.[Unit Price], OrderDetails.[Qty Return To Stock], OrderDetails.[Unit of Measure], OrderDetails.[Unit Weight], OrderDetails.[Taxable Flag], OrderDetails.[Select Code], OrderDetails.[GST Taxable Flag], OrderDetails.[Counter Type], OrderDetails.[Pick Sequence], OrderDetails.[Shelf Life], OrderDetails.[From Warehouse]

FROM OrderDetails LEFT JOIN Stock     ON OrderDetails.[Item Number] = Stock.[Item Number] WHERE (((Stock.Warehouse)="pk") AND ((Stock.[Date Invoiced]) Is Null) AND ((Stock.[Order Number]) Is Null))

GROUP BY OrderDetails.[Order Number], OrderDetails.[Sequence Number], OrderDetails.[Item Number], OrderDetails.Description1, OrderDetails.Description2, OrderDetails.[Qty Ordered], OrderDetails.[Qty To Ship], OrderDetails.[Qty Shipped], OrderDetails.[Unit Price], OrderDetails.[Qty Return To Stock], OrderDetails.[Unit of Measure], OrderDetails.[Unit Weight], OrderDetails.[Taxable Flag], OrderDetails.[Select Code], OrderDetails.[GST Taxable Flag], OrderDetails.[Counter Type], OrderDetails.[Pick Sequence], OrderDetails.[Shelf Life], OrderDetails.[From Warehouse], OrderDetails.[Order Number], OrderDetails.[Sequence Number]

HAVING (((OrderDetails.[Order Number])=109230))

ORDER BY OrderDetails.[Order Number], OrderDetails.[Sequence Number];

---------------------------------------------
Thanks,
0
Comment
Question by:Dan Flood
[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
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 2000 total points
ID: 12128852
Change this:

FROM OrderDetails LEFT JOIN Stock     ON OrderDetails.[Item Number] = Stock.[Item Number] WHERE (((Stock.Warehouse)="pk") AND ((Stock.[Date Invoiced]) Is Null) AND ((Stock.[Order Number]) Is Null))

to:

FROM OrderDetails LEFT JOIN (SELECT * FROM Stock WHERE Stock.Warehouse="pk" AND Stock.[Date Invoiced] Is Null AND Stock.[Order Number] Is Null) As A ON OrderDetails.[Item Number] = A.[Item Number]

Change any references to the Stock table in the rest of the query to A.
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12128864
BIG hunch, not carefully checked:  You might be getting fouled by the HAVING clause.  Have you tried adding you Order Number criteria to the WHERE clause instead to see if that returns what you expect (without a HAVING clause altogether)?
0
 

Author Comment

by:Dan Flood
ID: 12128881
Hi,

It happened without a having clause, but i just added that so when I am running the query it will limit the about of records... with or without it it is the same... but thanks!  I just tried it again.
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12128970
Did you try my suggestion?
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

715 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