SQL Join

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.

sql

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 :

  1. Inner Join —- selects all rows from both tables as long as there is a match between the columns in both tables.
  2. Left Join – returns all rows from the left table, even if there are no matches in the right table.
  3. Right Join – returns all rows from the right table, even if there are no matches in the left table.
  4. Full Join – combines the result of both LEFT and RIGHT joins.
  5. 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.
  6. Cartesian Join – returns the Cartesian product of the sets of records from the two or more joined tables.

Leave a Reply