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


Oracle Join SQL

Posted on 2014-08-12
Medium Priority
Last Modified: 2014-08-22

I have a select query in Oracle like the followings. The query brings up the matching records have both TBL1.col2 and TBL2.col2 not equal to null. But if the records have null values in both TBL1.col2 and TBL2.col2, it won't bring up the records. Is there any work aroud? I need to show them as well.

Select *
From TBL1 left join TBL2
on TBL1.col1=TBL2.col1 and TBL2.col2=TBL2.col2

Question by:mrong
LVL 78

Accepted Solution

slightwv (䄆 Netminder) earned 2000 total points
ID: 40256837
Two ways I can think of:
... and nvl(TBL1.col2,'ziggy')=nvl(TBL2.col2,'ziggy')

Just pick a word that should NEVER appear in the column.

on TBL1.col1=TBL2.col1 and ( TBL1.col2=TBL2.col2 or (TBL1.col2 is null and TBL2.col2 is null))
LVL 49

Expert Comment

ID: 40257392
afraid I don't get it: what is the purpose of "and TBL2.col2=TBL2.col2" at all

is it a mistake? did you mean:

Select *
From TBL1 left join TBL2
on TBL1.col1=TBL2.col1 and TBL1.col2=TBL2.col2 ?

If so  I would suggest:

Select *
From TBL1 left join TBL2
on TBL1.col1=TBL2.col1 and ( TBL1.col2=TBL2.col2 )  or ( TBL1.col2 is null and TBL2.col2 is null ))
LVL 32

Expert Comment

ID: 40258726
Can you provide some sample data with results that represent what you're seeing and what you would like it to be?

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

873 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