ORACLE JOINS
JOINS:
Join is combine columns from two or more tables into a single result set.
Joins are two type 1) sql joins
2)ANSI Joins
ANSI joins:
it introduced complete join syntax in the from clause.
joins are
equi joins
nonequi joins
self join
cross join
inner join
outer join
Equi joins:
To join the two or more tables using equality condition.
sql) select a.id,a.name
from a,b
where a.id=b.id;
Non equi joins:
to join the two or more tables other than equal to condition. like <,>,<=,=>,=!
select e.ename,e.sal
from emp e
where e.deptno <=20
/
Self Join:
Self join is a join in which a table is joined with it self.
Inner Join:
this will display all the records that have matched.
Cross Join or Cortesion Join:
to join two or more tables with out any condition.
Right Outer Join:
it will give left side matching rows and right side all rows.
Left Outer Join:
it will give right side matching rows and left side all rows.
Full Outer Join:
it will give both side matching and unmatching rows.
we have two take two tables like a and b.
SQL> select * from a; select * f rom b;
ID NAME ID NAME
---------- ----- ----- ----------
1 a 2 b
2 b 3 c
5 e 4 d
LEFT OUTER JOIN:
SQL> select id,a.name,b.name
from a left join b
using(id);
ID NAME NAME
--- ----- -----
2 b b
1 a
5 e
RIGHT OUTER JOIN:
SQL> select id,a.name,b.name
from a right join b
using(id);
ID NAME NAME
------- ------- -----
2 b b
3 c
4 d
INNER JOIN:
SQL> select id,a.name,b.name
from a inner join b
using (id);
ID NAME NAME
---- -------- ----------
2 b b
FULL OUTER JOIN:
select a.id,a.name,b.name
from a full outer join b
on (a.id=b.id)
/
----- --------- ----------
2 b b
c
d
1 a
5 e
CROSS JOIN:
SQL> SELECT A.ID,B.NAME,A.NAME
FROM A,B;
ID NAME NAME
---------- --------- -----
1 b a
1 c a
1 d a
2 b b
2 c b
2 d b
5 b e
5 c e
5 d e
9 rows selected.
Comments
Post a Comment