• Register

Joins in SQL

posted May 17 2 min read

Join is used to combine multiple tables, In this post, we are going to learn Different types of Joins available in the SQL and their Syntax

What is Join and why we need that?

Join is the keyword used to combine multiple tables and their columns, we are using the joins to get common records from the multiple tables using unique columns.

Different types of JOIN 

  1. Inner Join
  2. Left Join
  3. Right Join
  4. Full Join / Full outer Join

Inner Join

This type of Join used to get Matching values on the both/multiple tables,  INNER JOIN is the keyword used to archive this functionality

Select * from <table1>
Inner Join
<table2>
ON table1.column_name = table2.column_name;

 the above query will get the common record from the table1 and table2

Left Join

Left Join is used to get all the record from the Left table and get respective matching value on the right table, If doesn’t match then will return null. 

LEFT JOIN is the keyword used to archive this functionality

Select * from <table1>
Left Join <table2>
ON table1.column_name = table2.column_name;

this is also called  the LEFT outer join

Right Join

Right Join is used to get all the record from the Right table and get respective matching value on the Left table, If doesn’t match then will return null

 

Right JOIN is the keyword used to archive this functionality

Select * from <table1>
Right Join <table2>
ON table1.column_name = table2.column_name;

Full Join / Full outer Join

Full Join or Full outer Join both are same, it’s will return records matching on the left table or right table

Select *
from <table1>
Full outer Join <table2>
ON table1.column_name = table2.column_name;