Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Full Join Question

elmousa68May 11 2018 — edited May 13 2018

I have two tables

table1

---------

empno varchar2(5)

year varchar2(4)

field1 number(2)

field2 number(2)

table2

----------

empno varchar2(5)

year varchar2(4)

field3 number(2)

field4 number(4)

The primary key in both tables is (empno,year)

I have the following stats:

select count(*) from table1 where year='2013';

result: 195

select count(*) from table2 where year='2013';

result: 555

the inner join produces:

select count(*) from table1,table2 where table1.empno=table2.empno

and table1.year='2013' and table2.year='2013;

result: 40

so if I am to do an outer join between table1 and table2 on empno and year='2013'

I should get : 195+555-40=710

but when I run the following commands:

select count(*) from table1 full join table2 on table1.empno=table2.empno and

table1.year='2013' and table2.year='2013;

result:3584

select count(*) from table1 full join table2 on table1.empno=table2.empno where

table1.year='2013' and table2.year='2013;

result:40

both not producing the correct result.

What is the correct syntax for the outer join command given the table structure above? and,

what would be the correct syntax if there was a third table with the following structure

table 3

----------

empno varchar2(5)

year varchar(4)

field5 number(2)

field6 number(2)

again the primary key is (empno,year)

Thank you.

This post has been answered by Paulzip on May 11 2018
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 10 2018
Added on May 11 2018
11 comments
311 views