October 29, 2017
A SQL Join clause is used to combine rows from two or more tables, views, or materialized views based on a common field between them. A SQL join condition is used in the where clause of select, update, delete statements.
Syntax For Joining Two Table is :
SELECT col1, col2, col3…
FROM table_name1, table_name2
WHERE table_name1.col2 = table_name2.col1;
SQL Join Types :
There are different kinds of joins, which have different rules for the results they create. Listed below are the different types of SQL join :
- Inner Join - selects all rows from both tables as long as there is a match between the columns in both tables.
- Left Join – returns all rows from the left table, even if there are no matches in the right table.
- Right Join – returns all rows from the right table, even if there are no matches in the left table.
- Full Join – combines the result of both LEFT and RIGHT joins.
- Self Join – is used to join a table to itself as if the table were two tables, temporarily renaming at least one table in the SQL statement.
- Cartesian Join – returns the Cartesian product of the sets of records from the two or more joined tables.