Introduction
In this post, we will discuss how to work with joins and will explain the concept with examples in a simple way. I hope this is very useful for beginners and intermediate-level learners so as to help them understand the basic concept.
Prerequisites
Before we start with what a Join is, I assume that we are already aware of SQL table constraints in the database and with that, you can create the basic tables.
What are Joins in SQL?
Basically, SQL Joins are used to retrieve the data from two or more tables based on the common column between them which shows how the tables are related to each other using primary key and foreign key constraints based on the logical relationships.
For example purposes, we have created the following three tables.
Ex. SubExperts
CREATE TABLE [dbo].[SubExperts](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Subject] [nvarchar](50) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
SELECT * FROM [graphdemo].[dbo].[SubExperts]
Note. Please insert the record as it looks in the below table output.
Output

Ex. Ratings
CREATE TABLE [dbo].[Ratings](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Rating] [int] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
SELECT * FROM [graphdemo].[dbo].[Ratings]
Output
Ex. Employees
CREATE TABLE [dbo].[Employees](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[Age] [int] NULL,
[Salary] [money] NULL,
[SubExpertId] [int] NULL,
[RatingId] [int] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Employees] WITH CHECK ADD FOREIGN KEY([RatingId])
REFERENCES [dbo].[Ratings] ([Id])
GO
ALTER TABLE [dbo].[Employees] WITH CHECK ADD FOREIGN KEY([SubExpertId])
REFERENCES [dbo].[SubExperts] ([Id])
GO
SELECT * FROM [graphdemo].[dbo].[Employees]
Output

We have the following different types of Joins in SQL.
INNER JOIN in SQL
An inner join returns only the matching records between two tables and non-matching records are eliminated.

Syntax
SELECT ColumnList FROM Table1
INNER JOIN
Table2 on Condition
INNER JOIN
Table3 on Condition
Example
Select those employees with respective subject expertise and rating.
SELECT e.ID, e.Name, e.Age, e.Salary, s.Subject, r.Rating FROM [Employees] e
INNER JOIN
[SubExperts] s on e.SubExpertId = s.Id
INNER JOIN
[Ratings] r on e.RatingId = r.Id
Output









Kalai YarasiPosted Aug 16, 2018, 8:57 AM
Very good explanation
Shrimant TelgavePosted Aug 16, 2018, 12:25 AM
Good start and explained very well......keep it up.
Khaja MoizuddinPosted Aug 15, 2018, 4:14 AM
Good start Jitendra....
Sumit RajguruPosted Aug 15, 2018, 3:36 AM
Very good article. Thanx for sharing.
Suraj KumarPosted Aug 15, 2018, 2:00 AM
Good article thanks for sharing
Prasad KrishnaraoPosted Aug 14, 2018, 11:20 AM
Nice Article
Jignesh KumarPosted Aug 14, 2018, 11:10 AM
Well explained. pretty clear