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

x
?
Solved

Intersect Vs. Join query showing different results.

Posted on 2011-02-14
2
Medium Priority
?
867 Views
Last Modified: 2013-12-07
I have two tables table_a and table_b.

If i do a intersect query. it shows me say 100 records matched.
However, if i do a join it shows me 0 rows matched.

How is this possible. Since intersect and a join are the same thing?


select count(*)
from
(select table_a.col1,
      table_a.col2,
      table_a.col3,
      table_a.col4,
      table_a.col5
from table_a
INTERSECT
select table_b.col1,
      table_b.col2,
      table_b.col3,
      table_b.col4,
      table_b.col5
from table_b);
*******************
rows returned: 100
*******************


select table_a.*, table_b.*
from table_a, table_b
where table_a.col1 = table_b.col1
and  table_a.col2 = table_b.col2
and  table_a.col3 = table_b.col3
and  table_a.col4 = table_b.col4
and  table_a.col5 = table_b.col5

*******************
rows returned: 0
*******************
0
Comment
Question by:gram77
[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 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 34887194
INTERSECT allows to match on NULL values, while JOIN does NOT match on NULL values.


see this script:
with data1 as ( select 1 a, null b from dual union all select 2, 2 from dual)
, data2 as ( select 1 a, null b from dual union all select 2, 2 from dual)
select * from data1
intersect 
select * from data2
;

with data1 as ( select 1 a, null b from dual union all select 2, 2 from dual)
, data2 as ( select 1 a, null b from dual union all select 2, 2 from dual)
select * from data1
join data2
  on data1.a = data2.a
 and data1.b = data2.b
;

Open in new window

0
 

Author Comment

by:gram77
ID: 34887206
angelll:
ic, thx a lot
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
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 with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

705 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