SQL join is a technique used to combine two or more tables data by using a common column or key. It allows you to retrieve data from multiple tables based on a relationship between them.
SELECT column_name(s) FROM table1 JOIN table2 ON table1.column_name = table2.column_name;
INNER JOIN(or JOIN) returns only the matching rows between two tables. By default 'JOIN' keyword is treated as 'INNER JOIN'. Syntax :
SELECT column_name(s) FROM table1 JOIN table2 ON table1.column_name = table2.column_name;
LEFT JOIN (or LEFT OUTER JOIN) returns all the rows from the left table and the matching rows from the right table. If there is no match, the result will have null values for the right table columns. Syntax :
SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
RIGHT JOIN (or RIGHT OUTER JOIN) returns all the rows from the right table and the matching rows from the left table. If there is no match, the result will have null values for the left table columns. Syntax :
SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
FULL JOIN (or FULL OUTER JOIN) returns all the rows from both tables, with null values for the columns that do not have a match in the other table. Syntax :
SELECT column_name(s) FROM table1 FULL JOIN table2 ON table1.column_name = table2.column_name;
CROSS JOIN combines each row from one table with every row from another table. Typically, it is used to generate all possible combinations of rows from two or more tables. Syntax :
SELECT column_name(s) FROM table1 CROSS JOIN table2;
SELF JOIN is the type of join, where a table is joined with itself as if it were two separate tables. It is useful where a table contains hierarchical data or when comparing data within the same table. Syntax :
SELECT column_name(s) FROM table1 t1 JOIN table1 t2 ON t1.column_name = t2.column_name;
OR
SELECT column_name(s) FROM table1 t1, table1 t2 WHERE condition;
The four types of joins in SQL are: INNER JOIN, LEFT JOIN (or LEFT OUTER JOIN), RIGHT JOIN (or RIGHT OUTER JOIN), and FULL JOIN (or FULL OUTER JOIN).
Joining in SQL is the process of combining rows from two or more tables based on a related column between them.
To add three joins in SQL, you would specify the JOIN condition for each additional table you want to join with, typically in the FROM clause of your SQL query.
A full join in SQL returns all rows from both tables being joined, combining rows where there is a match and including unmatched rows from both tables.