SQL JOIN is used to combine data from two or more different table based on a common field between them in a relational database.
There are 5 types of JOIN:
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL JOIN
- CROSS JOIN
INNER JOIN: This SQL query returns all the common rows between the tables joined.
LEFT JOIN: This SQL query returns all the rows from the left table and the matched rows from the right table.
RIGHT JOIN: This SQL query returns all the rows from the right table and the matched rows from the left table.
FULL JOIN: This SQL query returns all the rows from both tables when there is a match in one of the tables.
FULL JOIN: This SQL query returns returns the Cartesian product of rows from tables in the join.
INNER JOIN SYNTAX:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
LEFT JOIN SYNTAX:
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
RIGHT JOIN SYNTAX:
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
FULL JOIN SYNTAX:
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
CROSS JOIN SYNTAX:
SELECT column_name(s)
FROM table1 CROSS JOIN table2;
0 Comment(s)