bing
Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
×
UPTO
50%
OFF!
Intellipaat
Intellipaat

What is Joins in SQL?

SQL Joins is used to combine rows of two or more tables by using common values.

Example:

Let us consider two tables first is Student details

NameRoll No.Marks
Akshay157
Charu268
Disha352
Eva468
Himanshu575
Jitesh688

Another table is Personal Detail.

NameCityPhone NoEmail Id
AkshayJaipur9543846521Akshay21@gmail.com
DishaBombay8532465892Disha@gmail.com
JiteshBanglore9684365125Jitesh1990@gmail.com

Let us see how to join the two tables in SQL

SELECT Name, City, Marks, Phone_no

FROM Student_detail, Personal_detail

WHERE Student_details.Name=Personal_detail.Name;
NameCityMarksPhone No
AkshayJaipur579543846521
DishaBombay528532465892
JiteshBanglore889684365125

 

Types of Joins in SQL

There are different types of Joins available in SQL:

  • Inner Join in SQL
  • Left Join in SQL
  • Right Join in SQL
  • Full Join in SQL

Inner Joins in SQL:

Inner SQL Join Query returns a value when there is a match in both the tables.

Watch this Inner Join in SQL video

Left Joins in SQL:

Left SQL Join Query returns all the values of the left table and matched the rows from the right table.

Watch this Left Join in SQL video

Syntax:

SELECT column_name

FROM table1

LEFT JOIN table2

ON table1.column_name=table2.column_name;

Example:

SELECT Student_details.Name, Address, Roll_no, Email_id

FROM Student_details

LEFT JOIN Personal_details

ON Student_details.Name= Personal_details.Name;
NameRoll No.AddressEmail Id
Akshay1JaipurAkshay21@gmail.com
Charu2NULLNULL
Disha3BombayDisha@gmail.com
Eva4NULLNULL
Himanshu5NULLNULL
Jitesh6BangloreJitesh1990@gmail.com

Right Joins in SQL:

Right SQL Join Query returns all the values of the right table and matched the rows from the left table.

Watch this Right Join in SQL video

Syntax:

SELECT column_name

FROM table1

RIGHT JOIN table2

ON table1.column_name=table2.column_name;

Example:

SELECT Personal_details.Name, Address, Roll_no, Email_id

FROM Student_details

RIGHT JOIN Personal_details

ON Student_details.Name= Personal_details.Name;

NameAddressRoll NO.Email Id
AkshayJaipur1Akshay21@gmail.com
DishaBombay3Disha@gmail.com
JiteshBanglore6Jitesh1990@gmail.com

FULL Joins in SQL:

Full SQL Join Query returns all the rows from the left table and the right table.

Watch this Full Join in SQL video

Syntax:

SELECT column_name

FROM table1

FULL OUTER JOIN table2

ON table1.column_name=table2.column_name;

Example:

SELECT Student_details.Name, Roll_no, Address

FROM Student_details

FULL OUTER JOIN Personal_details

ON Student_details.Name= Personal_details.Name;
NameRoll No.Address
Akshay1Jaipur
Charu2NULL
Disha3Bombay
Eva4NULL
Himanshu5NULL
Jitesh6Banglore

Previous Next

Download Interview Questions asked by top MNCs in 2019?

"0 Responses on Joins in SQL - SQL Joins"

    100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.
    top

    Sales Offer

    Sign Up or Login to view the Free Joins in SQL - SQL Joins.