SQL-Server-Inner-Join .

In this session i have discussed the SQL Server Inner-Join .

It is most commonly used join in sql server . It is used to retrieve the data from two or more than two tables . It is most important things one column same in both tables or more than two tables on which you are going to apply the inner join .

It retrieve the data when the common column of first table(tbl1) match with common column second table(tbl2) and create the new result set .


Inner Join syntax

    SELECT column_names  FROM tbl1
    INNER JOIN tbl2
    ON
    tbl1.column_name=tbl2.colum_name
    


Database Demo

The following data shown by Flight table of abc database .

Flight_Code Source Destination
A001 Delhi Kolkata
A002 Delhi Russia
A003 Mumbai USA
A004 Mumbai Australia

The below is Reservation table of abc database .

Flight_Code NO_Of_Seat
A001 100
A002 60
A003 50

Inner Join Example .

The below sql inner join code display the data that is match with common column from the Flight and Reservation table . Flight_Code is common is both table .

SELECT Flight.Flight_Code , Flight.Source , Flight.Destination ,
Reservation.No_Of_Seat FROM Flight
INNER JOIN Reservation
ON
Flight.Flight_Code=Reservation.Flight_Code
    

The output is look like below .

Flight_Code Source Destination No_Of_Seat
A001 Delhi Kolkata 100
A002 Delhi Russia 60
A003 Mumbai USA 50

You can also use the where condition in above inner join code . like below .

SELECT Flight.Flight_Code , Flight.Source , Flight.Destination ,
Reservation.No_Of_Seat FROM Flight
INNER JOIN Reservation
ON
Flight.Flight_Code=Reservation.Flight_Code where Flight_Code='A001'
    

Welcome to AndroidATPoint.

back image                     next image