0% found this document useful (0 votes)
26 views19 pages

Joins

The document discusses different types of joins that can be used to retrieve data from multiple database tables, including inner joins, outer joins, self joins, and cross joins. Inner joins include equi joins and non-equi joins. Outer joins include left, right, and full outer joins.

Uploaded by

ajithram275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views19 pages

Joins

The document discusses different types of joins that can be used to retrieve data from multiple database tables, including inner joins, outer joins, self joins, and cross joins. Inner joins include equi joins and non-equi joins. Outer joins include left, right, and full outer joins.

Uploaded by

ajithram275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

JOINS

JOINS ARE USED TO RETRIEVED DATA FROM


MULTIPLE TABLES. IN ALL DATABASES WHEN WE
ARE
JOINGIN "N" TABLES THEN WE MUST USE "N-1"
JOINING CONDITIONS.
Inner join
1. Equi joing
2. Non equi join

1. Self join
2. Cross join
3. Natural join

These 4 joins are also called as "8i joins".


9i joins or ansi joins.
Outer join
1. Left outer join
2. Right outer join
3. Full outer join
1. Equi join
Based on equality condition we are retrieving
data from multiple tables. Here joining conditional
columns must belongs to same datatype.
syntax:
select col1, col2,....from table_name1,
tablename2where tablename1.common column_name=
table_name2.Common column_name;
EX:
select e.employee_id,d.department_id
from emp2 e join departments d
on e.employee_id= d.department_id;
2. Non Equi Join:
Basedon other than equality
condition(notequalto,>,<,>=,<=,between,in,....) we
can retrieve data from multiple tables.

syntax:
select col1, col2,....from table_name1,
tablename2where tablename1.common column_name
> table_name2.Common column_name;
EX:
select e.employee_id,d.department_id
from emp2 e join departments d
on e.employee_id>=d.department_id;
1.SELF JOIN:
Joining a table to itself is called "self join".
Here joining conditional columns
must belongs to same datatype. Before we are
using self join we must create alias names for the table
in "from" clause.
Syntax:
select column_name,from table_name1 join table_name2
On table1.column_name=table2.column_name;

EX:

selecta.first_name,a.employee_id,b.first_name,b.employee_id
from emp2 a join emp2 b on a.employee_id = b.manager_id;
2.Cross join:
cross join is implemented based on Cartesian
product that’s the internal join return more duplicate data.

Syntax:
select from tablename aliasname1 cross join tablename
aliasname2;

EX:
select * from emp2 e cross join employees d;
3. Natural Join
This join returns only matching rows. When we are
using "Natural Join" then we are not allowed to use joining
condition.
In this case oracle server only internally uses joining
condition.
Syntax:
select * from tablename1 natural join tablename2;

EX:
select *from employees e natural join departments d;
2.Left Outer Join
This join always reuturns all rows from left
side table and matching rows from reight side
table and also returns "NULL" values in place of
non-matching rows in another table.
Syntax:
select column_name from table_name1 left outer
join table_name2 on
table1.column_name=table2.columnname;

EX :
select e.employee_id,d.department_id
from employees e left join departments d on
e.employee_id = d.department_id;
3. Right Outer Join
This Join returns all rows from right side table and
matching rows from left side table
also returns null values in place of "non-matching" rows
in another table.
Syntax:
select column_name from table_name1 right outer join
table_name2 on table1.column_name=table2.columnname;
EX :
select e.employee_id,d.department_id
from employees e left join departments d on e.employee_id
= d.department_id;
4. Full Outer Join
This join returns all data from all the
tables it is the combination of left and right outer
joins.
This join always returns matching and non-
matching rows.
Syntax:
select column_name from table_name1 full outer
join table_name2 on
table1.column_name=table2.columnname;

EX:
select e.employee_id,d.department_id
from employees e full outer join departments d on
Thank You

You might also like