Professional Documents
Culture Documents
Joins:-
-----
Equi joins:-
------------
left join :-
---------
--> we have to make '+' within brackets to right hand side table
select
a.cust_id,
a.cust_name,
a.mob_no,
a.email,
a.country_id,
b.country_name
from customer a, country b
where a.country_id=b.country_id(+);
--> But in ANSI method you can directly mention left join or left outer join in the
query.
Right join:-
----------
--> we have to make '+' within brackets to left hand side table
select
a.cust_id,
a.cust_name,
a.mob_no,
a.email,
b.country_id,
b.country_name
from customer a, country b
where a.country_id(+)=b.country_id;
--> But in ANSI method you can directly mention right join or right outer join in
the query.
--> In realtime mostly we use ANSI methond, performance wise ANSI method gives
better result
--> While joining 3 or more tables select all the required columns from all tables
and make aliases to the tables then use where condition.
--> You cannot be able to mention more than 2 tables in from clause in ANSI method,
if you want to join more than 2 tables in ANSI method then
you have to do join on first two tables and then the next table and so on.
Self join:-
---------
--> Doing join on one table of same data is called self join
ex:-
select
e1.employee_id,e1.employee_name,
'Reports to',
e2.employee_id,e2.first_name
from employees e1, employees e2
where e1.manager_id=e2.employee_id order by 1;
Non-equi join:-
-------------
--> Whenever you are making join with non-equal(<,>,<=,>=,!=) condition is called
non-equi join.
--> It's same as cross join but here you won't get the matched records from the
table, you only get the non matched records.
--> Normally we do not write any non equi joins in realtime. we will write only
equi joins. Discussed joins above all are equi joins.
ex:-
select
e.emplouee_id,
e.first_name,
e.email,
e.salary,
e.deparmemt_id,
d.department_name,
d.location_id
from employees e, departments d
where e.deparment_id!=d.department_id;