I’m going to show you How to Use SQL Server Inner Join, I will tell you clearly with examples. I think more than beginners facing problem to understand Inner Join. They are don’t have understood, how Inner Join work it in SQL Server?
Basically, you will use Inner Join to see Multi Tables records, but you have used relationships. That’s very simple process to make tables and include foreign key or relationship. After complete, these process to you will use Inner Join and display record as well.
Below, I have shared Student Registration Form database, I have used Inner Join to display record as well. There are many tables and columns available in Student Registration Form. You can follow my tutorial then you will easily understand it.
SQL Server Inner Join with Examples
First of All, I have made Country Table and Used Two Columns Namely C_ID and CountryName. Then I have inserted Four Records Below Screenshot and query shared.
create table Country(C_ID int primary key identity (1,1), CountryName varchar(50))
insert into Country values ('USA'),('UK'),('UAE'),('Turkey')
select * from Country
Second Steps: I have made Province Table and Used Three Columns Namely P_ID, Province Name and Also C_ID. C_ID Make Relationship with Country Table.
create table Provice(P_ID int primary key identity (1,1),
ProvinceName varchar(50), CID int foreign key references Country(C_ID))
insert into Provice values ('Alabama',1),('Alaska',1),('American Samoa',1),('Arizona',1)
select * from Provice
Third Steps: I have made City Table, and Used Three Columns Namely Ct_ID, City Name, and Finally add P_ID. P_ID Column makes relationship with Province Table.
create table City(Ct_ID int primary key identity (1,1),
CityName varchar(50), PID int foreign key references Provice(P_ID))
insert into City values ('Mobile',1),('Dothan',1),('Aubrun',1),('Selma',1)
select * from City
Fourth Steps: I have made Registration Table and used Eight Columns Namely R_ID, Name, FName, Gender, DOB, CT_ID, PR_ID and Finally CI_ID.
In this Table, I have made relationship Three above tables like Country, Province, and City. These Table First Column used with Relationship on this Table.
create table Registration (R_ID int primary key identity (1,1),
Name varchar (50), FName varchar(50),
Gender varchar(50), DOB varchar(50),
CT_ID int foreign key references Country(C_ID),
PR_ID int foreign key references Provice(P_ID),
CI_ID int foreign key references City(Ct_ID))
insert into Registration values ('Aamir','Kareem Bux','Male','05-05-1995',1,1,1)
select * from Registration
Fifth Steps: Above you have seen record doesn’t readable. So I use Inner Join to displays readable record.
SQL Server Inner Join
select Registration.R_ID,Registration.Name, Registration.FName,
Registration.Gender, Registration.DOB, Country.CountryName, Provice.ProvinceName,City.CityName
inner Join Country
inner join Provice
inner join City
After Used Inner Join you have seen record have been displayed as well. Basically, Join is used to matched columns IDs, then display record with the help of ID Numbers.
In this Tutorial, I have made fourth tables and made the Inner join, then you have seen record has been displayed successfully. Furthermore, If you have any question/suggestion kindly comment me on below comment section.
I will reply to you very soon, Thanks for the read and visit my blog. Don’t be forget to Subscribe and Follow on my Social Networks.
You May Also Like: