Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Difference between non equi join and outer joins

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-10-08, 08:17
Olusoga Olusoga is offline
Registered User
 
Join Date: Nov 2007
Posts: 29
Difference between non equi join and outer joins

Dear all,
please can someone explain to me the difference between outer joins, non equi join and inner joins in details please. Also kindly give me an idea of the scenarios where they apply.
For example, I have two tables A and B, their join column is centre that is

A.centre=B.centre

Now i want to retrieve records from A that do not have centres in B.
Which join type do i use here.
Thanks
Olusoga
Reply With Quote
  #2 (permalink)  
Old 01-10-08, 08:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
use a LEFT OUTER JOIN with an IS NULL test on the right join column


__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 01-10-08, 09:33
Olusoga Olusoga is offline
Registered User
 
Join Date: Nov 2007
Posts: 29
difference between outer join and non eui join

Please i forgot to mention that I am running oracle 10g database.
Also where does this outer join operator (+) come into play.
I don't seem to get the left outer join with IS null solution.
Thanks
Reply With Quote
  #4 (permalink)  
Old 01-10-08, 11:36
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 848
In my opinion, a subselect is more appropriate here. I think it communicates your desire in finding recs from one table which don't exist in the other

Code:
select * from tabl1 A where not exists (select 1 from tabl2 B where A.centre=B.centre)

An outer join, again in my opinion, is better reserved for cases where you are interested in seeing columns from the inner table.

--=cf
Reply With Quote
  #5 (permalink)  
Old 01-10-08, 14:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
even more important is having more than one arrow in your quiver
Code:
select A.* from A left outer join B on B.centre = A.centre where B.centre is null
you never know when one of them will outperform the other

__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #6 (permalink)  
Old 01-10-08, 14:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
Quote:
Originally Posted by Olusoga
Also where does this outer join operator (+) come into play.
it should never, not ever, ever again

that horrid syntax is from the last millenium and you should be using explicit JOIN syntax instead

__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #7 (permalink)  
Old 01-10-08, 14:44
beilstwh beilstwh is offline
Registered User
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 1,642
Quote:
Originally Posted by r937
it should never, not ever, ever again

that horrid syntax is from the last millenium and you should be using explicit JOIN syntax instead


Using the (+) join in oracle has always worked and up until oracle 10G, the JOIN syntax has had a number of bugs. However, there are things that the join syntax can do that the old (+) could never do such as outer joining to more then one table. In 10G and above, I would use JOIN, before I would use (+)
__________________
Bill
Cream always raises to the top, and so does the scum!!
Reply With Quote
  #8 (permalink)  
Old 01-14-08, 09:52
Olusoga Olusoga is offline
Registered User
 
Join Date: Nov 2007
Posts: 29
Thumbs down outer join

Hi
What the left outer join seems to be doing is to retrieve the rows that satisy the join condition as well as the rows from Table A where column values is null in B.
What I want is ONLY the rows in table A that are not present in table B based on their join condition. I do not want values that satisfy the join condition at all.
Please help out
Thanks a million
\'SOga
Reply With Quote
  #9 (permalink)  
Old 01-14-08, 10:48
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 3,569
Select Key From Table_a
Minus
Select Key From Table_b
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
Reply With Quote
  #10 (permalink)  
Old 01-14-08, 11:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
Quote:
Originally Posted by Olusoga
Hi
What the left outer join seems to be doing is to retrieve the rows that satisy the join condition as well as the rows from Table A where column values is null in B.
then you do not understand the LEFT OUTER JOIN with the IS NULL condition

what the LEFT OUTER JOIN is actually doing is trying to find rows from B that satisfy the join condition, and if none are found, it sets the B columns in the result set to NULL

this is what the IS NULL condition in the WHERE clause is used for -- to find result rows where the join column from B has been set to NULL because there was no match

only these result rows are returned -- i.e. this is exactly what you wanted, rows from A which have no matching rows in B
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #11 (permalink)  
Old 01-15-08, 05:59
Olusoga Olusoga is offline
Registered User
 
Join Date: Nov 2007
Posts: 29
left outer join

Thanks r937 and chuck_forbes.
The two didfferent queries worked fine but i noticed in the query response time that the left outer join query performed faster in (104 secs) than the subquery (189secs). Thanks all
Reply With Quote
  #12 (permalink)  
Old 01-15-08, 10:29
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 848
Did you try executing the same queries repeatedly? Depending upon which one is executed first, as well as other factors, can affect timing. They also may perform differently in your production environment vs dev if you have different data, and thus different statistics. ---=cf
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On