3. Join
A JOIN clause is used to combine rows
from two or more tables, based on a
related column between them.
4. Types of SQL JOINs
1. Equi- Join
2. Non-Equi- Join
3. Natural Join
4. Cross Join
5. Left Join
6. Right Join
7. Full Join
8. Self Join
5. Equi JOIN
EQUI JOIN performs a JOIN against equality or matching column(s)
values of the associated tables. An equal sign (=) is used as comparison
operator in the where clause to refer equality.
Syntax
SELECT column_list
FROM table1 , table2....
WHERE table1.column_name = table2.column_name;
8. Non-Equi JOIN
The NON EQUI JOIN uses comparison operator instead of the
equal sign like >, <, >=, <= along with conditions.
Syntax
SELECT column_list
FROM table1 , table2....
WHERE table1.column_name != table2.column_name;
11. Natural JOIN
The NON EQUI JOIN uses comparison operator instead of the
equal sign like >, <, >=, <= along with conditions.
Syntax
SELECT column_list
FROM table1 Natural Join table2;
15. INNER JOIN
Syntax:
SELECT column_name(s)
FROM table1
Inner JOIN table2
ON table1.column_name = table2.column_name;
The INNER JOIN keyword selects records that have
matching values in both tables.
17. LEFT JOIN
The LEFT JOIN keyword returns all records from the left table
(table1), and the matched records from the right table (table2).
The result is NULL from the right side, if there is no match.
Syntax
SELECT column_name(s)
FROM table1
Left JOIN table2
ON table1.column_name = table2.column_name;
20. RIGHT JOIN
The RIGHT JOIN keyword returns all records from the right table (table2),
and the matched records from the left table (table1). The result is NULL
from the left side, when there is no match.
Syntax:
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
23. FULL JOIN
MySQL does not support FULL JOIN, so you have to combine
JOIN, UNION and LEFT JOIN to get an equivalent.
24. SELF JOIN
“A self JOIN is a regular join, but the table is
joined with itself.”
Syntax:
SELECT column_name / *
FROM table1 t1, table1 t2
Where Condition;
T1 and T2 are different table aliases for the same table.