Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQL 13

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

left outer join:

this join return all rows from left side table


and matching rows from rightside table and
also return null values in place of non matching
rows in another table

SQL> create table z1(a varchar2(10),b varchar2(10),c varchar2(10));

Table created.

SQL> insert into z1 values('x','y','z');

1 row created.

SQL> insert into z1 values('p','q','r');

1 row created.

SQL> select * from z1;

A B C
---------- ---------- ----------
x y z
p q r

SQL> create table z2(a varchar2(10),b varchar2(10));

Table created.

SQL> insert into z2 values('x','y');

1 row created.

SQL> insert into z2 values('s','t');

1 row created.

SQL> select * from z2;

A B
---------- ----------
x y
s t

SQL> select * from z1;

A B C
---------- ---------- ----------
x y z
p q r

SQL> select * from z2;

A B
---------- ----------
x y
s t

SQL> select * from z1 left outer join z2


2 on z1.a=z2.a and z1.b=z2.b;

A B C A B
---------- ---------- ---------- ---------- ----------
x y z x y
p q r

right outer join:


this join return all rows from right side table
and matching rows from leftside table and
also return null values in place of non matching
rows in another table

SQL> select * from z1 right outer join z2


2 on z1.a=z2.a and z1.b=z2.b;

A B C A B
---------- ---------- ---------- ---------- ----------
x y z x y
s t

full outer join:


this join returns all rows from all tables
because it is combination of left,right outer
join
this join also returns null values in place
of non matching rows on other table

SQL> select * from z1 full outer join z2


2 on z1.a=z2.a and z1.b=z2.b;

A B C A B
---------- ---------- ---------- ---------- ----------
x y z x y
s t
p q r

natural join:
this join returns matching rows only,this join
performance is very high comapred to inner join

note:
in this join we are not required to use joining
condition explicitly,but in this case
resource table must have common column

SQL> select * from z1 natural join z2;

A B C
---------- ---------- ----------
x y z

note:
when ever we are using natural join then we
are not allowed to use aliesname to joining
conditional column because natural join
internally uses using clause
cross join:

SQL> select ename,sal,dname,loc from emp cross join dept;

select * from emp;


14 rows
select * from dept;
12 rows

14*12=168 rows

joining more than two tables:

8i joins:
syntax:
select col1,col2.... from tab1.tab2,tab3
where tab1.comcol=tab2.comcol
and
tab2.commcol=tab3.comcol

9i joins:
select co11,col2,.....
from tab1 join tab2
on tab1.comcol=tab2.comcol
join tab3
on tab2.comcol=tab3.comcol

You might also like