[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Oracle 10g Outer Left Join issue

Posted on 2012-09-20
Medium Priority
Last Modified: 2012-09-20

I have having issues with what should be a simple outer left join. Please comment what is wrong

Select H.Item_Code, H.Item_Des1, D.item_qty_bkd_qty
from M_item_H H
LEFT OUTER JOIN M_ITEM_D1 D on H.Item_code = D.Item_code
and H.cust_code = D.cust_code
and H.comp_code = D.comp_code
where D.item_qty_Bkd_lev_num = 2
and h.comp_Code = 'W1'
and h.Cust_Code = 'TIMWEB'

Expecting all records from H
and only matching from D, null otherwise

Current output is = and returns only values where
where D.item_qty_Bkd_lev_num = 2
Question by:JDCam
  • 2
LVL 25

Accepted Solution

lwadwell earned 2000 total points
ID: 38417706
That is correct ... the left outer join returns null to the WHERE clause when no row is found.
The WHERE clause then cancels that by doing D.item_qty_Bkd_lev_num = 2

Use the D.item_qty_Bkd_lev_num = 2 in the ON e.g.
LEFT OUTER JOIN M_ITEM_D1 D on H.Item_code = D.Item_code
AND D.item_qty_Bkd_lev_num = 2
and H.cust_code = D.cust_code
and H.comp_code = D.comp_code
LVL 25

Expert Comment

ID: 38417715
If D.item_qty_Bkd_lev_num is never null ... you could also do it the WHERE clause
WHERE (D.item_qty_Bkd_lev_num = 2 or D.item_qty_Bkd_lev_num IS NULL)

Author Closing Comment

ID: 38417819

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

872 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