Mark As Completed Discussion

A Reference On Joins

When writing SQL, a situation might occur where you have to combine the rows of multiple columns to execute your query. The JOIN clause is used in this case to join two or more tables based on a mutual column.

In order to join two tables, there must be a column in table1 which is also present in table2. Often this will be a primary key column on table1 that is found as a foreign key column on table2, or vice versa.

There are four types of joins:

  1. INNER JOIN
  2. RIGHT OUTER JOIN
  3. LEFT OUTER JOIN
  4. FULL OUTER JOIN

INNER JOIN

The INNER JOIN clause is used when we need the records which have the same value of the mutual column in both the tables.

Joins Reference

RIGHT OUTER JOIN

RIGHT OUTER JOIN is used when we wish to have all records from the "right" table, and just the records which have the same value of the mutual column from the left table.

Joins Reference

LEFT OUTER JOIN

LEFT OUTER JOIN is used when we wish to have all records from the left table, and just the records which have the same value of the mutual column from the right table.

Joins Reference

FULL OUTER JOIN

FULL OUTER JOIN is used when we wish to have all records from both the tables, whether the records have the same value of the mutual column or not.

Joins Reference