Database Systems: Sonal Pandey M.E. CSE Dept. NITTTR, Chandigarh
Database Systems: Sonal Pandey M.E. CSE Dept. NITTTR, Chandigarh
Database Systems: Sonal Pandey M.E. CSE Dept. NITTTR, Chandigarh
Sonal Pandey
M.E. CSE Dept.
NITTTR, Chandigarh
1
• A JOIN is a means for merging fields from two tables by using values common to each. SQL Joins
condition is a part of the sql query that fetch/retrieve rows(data) from two or more tables.
tbl_department
The Different Types of Joins in SQL Server
1 - INNER JOIN : A Inner Join is a type of sql join which returns all the rows from both
tables where there is a match. Means return matching records for both tables.
2 - SELF JOIN : A Self Join is a type of sql join which is used to join a table to itself. In
this join both the columns belong to the same table.
Right outer Join : In This join returns all the rows from the right table in
conjunction with the matching rows from the left table.
Left outer Join : In This join returns all the rows from the left table
in conjunction with the matching rows from the right table.
An outer join does not require each record in the two joined tables
to have a matching record. The joined table retains each record—
even if no other matching record exists. Outer joins subdivide
further into left outer joins, right outer joins, and full outer joins,
depending on which table(s) one retains the rows from (left, right, or
both).
Left Outer Join
The result of a left outer join (or simply left join) for table A and B always contains all
records of the "left" table (A), even if the join-condition does not find any matching record
in the "right" table (B).
This means that if the ON clause matches 0 (zero) records in B, the join will still return a
row in the result—but with NULL in each column from B.
This means that a left outer join returns all the values from the left table, plus matched
values from the right table (or NULL in case of no matching join predicate).
If the right table returns one row and the left table returns more than one matching
row for it, the values in the right table will be repeated for each distinct row on the left
table.
Employee
Employee =X Dept
Dept
Left Outer Join (Example)
Right Outer Join
A right outer join (or right join) closely resembles a left outer join,
except with the treatment of the tables reversed. Every row from the
"right" table
(B) will appear in the joined table at least once. If no matching row from the
"left" table (A) exists, NULL will appear in columns from A for those
records that have no match in B. A right outer join returns all the values
from the right table and matched values from the left table (NULL in case
of no matching join predicate).
Employee
Employee X= Dept
Dept
Full Outer Join
Dept
Full Outer Join (Example)
Equijoin