Arrow

SQL Joins

AuthorHariom Prajapati

Pubish Date03 Jul 2022

categoryMySql

It is used to combine rows from two or more tables based on a related column between them.

 

Inner Join

The inner join keyword select all the records which have maching value in both of the tables.

sql inner join

Syntax -

select * from table1_name 
inner join table2_name 
on table1_name.table1_column_name= table2_name.table2_column_name;

 

Note: Table1 must have a primary key and table2 must have a foreign key.

sql inner join

 

Left Join

The left join  get all the data/record from left table1 and only get match data/record from the right table 2.

If there is no data match from right table 2 then the result will be NULL.

sql left join

Syntax -

select * from table1_name 
left join table2_name 
on table1_name.table1_column_name= table2_name.table2_column_name;

 

Note: Table1 must have a primary key and table2 must have a foreign key.

sql left join

 

Right Join

The right join  get all the data/record from right table 2 and only get match data/record from the left table 1 table.

If there is no data match from left table 1 then the result will be NULL.

sql right join

Syntax -

select * from table1_name 
right join table2_name 
on table1_name.table1_column_name= table2_name.table2_column_name;

 

Note: Table1 must have a primary key and table2 must have a foreign key.

sql right join