Вы находитесь на странице: 1из 2

What is Join? Explian about Inner and Outer Joins?

Join:To retrieve data from two or more tables we can use Join condition.
Join can be used in either From or Where clause. But specify Join in From clause
is recommended. We can also use Where and Having clause to filter more.
Joins can be categorized as :
- Inner Join -> Equi Join & Natural Join
- Outer Join -> Left Outer Join, Right Outer Join & Full Join
- Cross Join
- Self Join
Inner Join: This Join is used to get matched records from both the tables. To re
trieve matched records we will use comparison operators (i.e. =, < >).
We can also call Inner Join as Natural Join or Equi Join.
Syntax:
Select emp.empid, emp. salary, ph.phnumber
from employee emp Inner Join phone ph
on emp.empid = ph. empid
where emp.salary > 1000
Outer Join : To retrieve matched and unmatched records from both the tables we w
ill use Outer Join. Unmatched rows will display as NULL from both table.
Outer Join can be categorized as: Left Join , Right Join and Full Join.
Left Outer Join: In Left Outer Join, all the rows in the first-named table, i.e
. left table, which appears leftmost in the JOIN clause, are included. Unmatched r
ows in the right table do not appear.
SYNTAX:
Select emp.empid, emp. salary, ph.phnumber
from employee emp Left Join phone ph
on emp.empid = ph. empid
where emp.salary > 1000
Right Outer Join: Right Outer Join: In Right Outer Join, all the rows in the se
cond-named table, i.e. right table, which appears rightmost in the JOIN clause are
included. Unmatched rows in the left table are not included..
SYNTAX:
Select emp.empid, emp. salary, ph.phnumber
from employee emp Left Join phone ph
on emp.empid = ph. empid
where emp.salary > 1000
Full Outer Join: In Full Outer Join, all the rows in all joined tables are inclu
ded, whether they are matched or not.
What is Cross Join?
Answer:
It is a Teradata specified Join, which is used as equivalent to product join.
There is no On clause in case of CROSS join
SELECT EMP.ename , DPT.Dname
FROM employee EMP
CROSS JOIN
Department DPT
WHERE
EMp.deptno = DPT.depto ;
Self Join: A table can be joined to itself in a self-join.
For example, you can use a self-join to find out the authors in Oakland, Califor
nia who live in the same ZIP Code area.
SELECT au1.au_fname, au1.au_lname, au2.au_fname, au2.au_lname FROM authors au1 I
NNER Jauthors au2
ON au1.zip = au2.zip
WHERE au1.city = 'Oakland'
ORDER BY au1.au_fname ASC, au1.au_lname ASC .

Вам также может понравиться