Joins : A difference in extracting the data

Joins : A difference in extracting the data

Joins are used to combine tuples (rows) from multiple tables. There can be multiple numbers of joins in the query statement. The tables are interlinked by joins using Primary Key and Foreign Key.

Joins can be of two types:

  1. Inner joins
  2. Outer joins

Inner joins are used to extract the common records where the keys are matching in both the tables.

 

The general syntax for performing inner join is,

SELECT column-names  FROM table-name1 INNER JOIN table-name2

ON column-name1 = column-name WHERE condition

Outer joins are generally used for extracting the matching records as well as the other records in the specific table. They are categorized into three types:

  • Left Outer join
  • Right Outer join
  • Full Outer join

Left Outer join pulls all the records from the left table as well as the matching records in the right table.

The general syntax for performing left outer join is,

SELECT column-names FROM table-name1 LEFT OUTER JOIN table-name2 ON column-name1 = column-name2 WHERE condition

Right Outer join pulls all the records from the right table as well as the matching records in the left table.

The general syntax for performing right outer join is,

SELECT column-names FROM table-name1 RIGHT OUTER JOIN table-name2 ON column-name1 = column-name2 WHERE condition

Full Outer join pulls all the matching records from both tables as well as the unmatched records.

The general syntax for performing full outer join is,

SELECT column-names FROM table-name1 FULL OUTER JOIN table-name2 ON column-name1 = column-name2 WHERE condition

References: https://www.dofactory.com/sql/join

 

By

Cassin Thangam Edwin

 

Leave a Reply

Your email address will not be published. Required fields are marked *