In SQL a join clause combines columns form one or more tables by using values common to each other. This is very useful when we have to access information across multiple tables with some relation between them.

Basically there are 6 types of joins available in SQL:

  1. Inner join:  
    Returns rows when there is a match in both tables.
    SELECT *
    FROM table-A INNER JOIN table-B
    ON table-A.column_name = table-B.column_name;

Inner join

  1. Left join:  
    Returns all rows from the left table, even if there are no matches in the right table.
    SELECT *
    FROM table-A
    LEFT JOIN table-B
    ON table-A.column_name=table-B.column_name;

Left join

  1. Right join:  
    Returns all rows from the right table, even if there are no matches in the left table.
    SELECT *
    FROM table-A
    RIGHT JOIN table-B
    ON table-A.column_name=table-B.column_name;

Right join

  1. Full join (outer):
    Returns rows when there is a match in one of the tables.
    SELECT *
    FROM table-A
    FULL OUTER JOIN table-B
    ON table-A.column_name=table-B.column_name;
    
    

Full join

  1. Self-join:  
    Join a table itself. This is done by temporarily renaming at least one table in SQL, making a single table act as two.
    SELECT a.column_name, b.column_name …
    FROM table-A a, table-B b
    WHERE a.common_filed = b.common_field;
  2. Cross/ Cartesian join:  
    returns the Cartesian product of the sets of records from the two or more joined tables.
    Select table-A.column-1, table-B.column2 …
    From table-A, table-B …

Related

DataBase

Redis msi installer for windows, by Microsoft Open Teach group

DataBase

Join clause combines columns form one or more tables by using common values.

keyboard_arrow_up