In this article, we will learn about Joins in SQL Server. I will explain all SQL Joins with an example.
Introduction
Joins are used to fetch data from two or more two tables based on some conditions. Joins are one of the most important concepts of SQL Server. We can retrieve data from multiple tables using Joins.
Classification Of Joins in SQL

When we retrieve the data from multiple tables with one keyword condition then this is called ANSI format join.
When we retrieve data from multiple tables based on where keyword condition then it is called NON-ANSI format Joins.
Note. Inner Join is the default Join in Joins.
Syntax of Joins
SELECT /* <List of columns> */
FROM Tablename1
<Join> Tablename2
ON <Join Condition>
WHERE <Where Condition>;
Let us understand Joins with an example.
Create Two Tables in SQL
CREATE TABLE customer (
Id INT,
Name VARCHAR(50),
Mobile INT,
CustomerId INT
);
CREATE TABLE company (
CompanyId INT,
CompanyName VARCHAR(50),
Salary DECIMAL(6,2)
);
Insert some data into Tables in SQL
-- Insert into customer table
INSERT INTO customer VALUES (1, 'A', 89898989, 101);
INSERT INTO customer VALUES (2, 'B', 78787877, 102);
INSERT INTO customer VALUES (3, 'C', 98323232, 103);
-- Insert into company table
INSERT INTO company VALUES (101, 'C1 Tech', 5000);
INSERT INTO company VALUES (102, 'Cone Tech', 1000);
INSERT INTO company VALUES (104, 'Netvision Tech', 3500);
INSERT INTO company VALUES (105, 'S Tech', 1500);
Equi Join in SQL
When we retrieve the data from multiple tables based on an equality condition then this is called an Equi Join.
This Join process supports only one operator equal Operator (=)
When we use Equi Join we should maintain a common column name and that column should contain the same data type.
Example
SELECT c.id, c.name, c.mobile, c.CustomerId, com.Companyid, com.CompanyName, com.Salary
FROM customer c
INNER JOIN company com ON c.CustomerId = com.Companyid;
Result

Alias Name
Alias Name is a duplicate or Alternative Name.
We can define alias names in two levels,
- Column-level alias name
- Table-level alias name
When we create a duplicate name for a column then it is called column level alias name.
Syntax
<Column Name> AS <column alias Name>
When we create the alternative name for the tables in the database then it is called table level alias name.
Syntax
<TableName> AS <TableAliasName>
Note. Alias names are mostly implemented in Joins.
Inner Join in SQL
Inner Join is used for retrieving data from multiple Tables. When we use inner Join we should use a common column name and the datatype is also the same in the Table.
Example
select * from customer c inner join company com on c.CustomerId=com.Companyid
Result

Outer Join in SQL
Outer Join is an extension of the Inner Join.
In Inner Join mechanisms, the user will get matching data from the Tables and leave unmatching data from the Tables.
To overcome the drawback we use the Outer Join. By using outer we can retrieve matching data and also unmatch data from the tables at the same time.








Join the conversation! Your thoughts help the community grow.