What is Inner Join (or) Join in SQL Server?
Introduction:
In this article i will explain what is INNER JOIN in SQL Server.
Description:
In previous articles i explained what are joins and other SQL Server topics. Now i will explain what is INNER JOIN in SQL Server.
An inner join is a join in which the values in the columns being joined are compared using a comparison operator.
In the ISO standard, inner joins can be specified in either the FROM or WHERE clause. This is the only type of join that ISO supports in the WHERE clause. Inner joins specified in the WHERE clause are known as old-style inner joins.
Syntax:
Select *
From Table1
inner join Table2
on Table1.Col1 = Table2.Col1
Here you will get data from both the tables where Col1 of Table1 is equivalent to Col1 of Table2. Here *(star) means you will get data from both the tables.
Note: Here you can use alias for tables. See the following example:
Select T1.*
From Table1 T1
inner join Table2 T2
on T1.Col1 = T2.Col1
Now you will get Table1 data where Col1 of Table1 is equivalent to Col1 of Table2.
Select T2.*
From Table1 T1
inner join Table2 T2
on T1.Col1 = T2.Col1
Now you will get Table2 data where Col1 of Table1 is equivalent to Col1 of Table2.
Query using INNER JOIN:
Select *
From Table1 T1
inner join Table2 T2
on T1.Col1 = T2.Col1
Query using JOIN:
Select *
From Table1 T1
join Table2 T2
on T1.Col1 = T2.Col1
The question is what is the difference between above two syntax.
Here is the answer - They are equal to each other. There is absolutely no difference between them. They are equal in performance as well as implementation. JOIN is actually shorter version of INNER JOIN.
Personally I prefer to write INNER JOIN because it is much cleaner to read and it avoids any confusion if there is related to JOIN. For example if users had written INNER JOIN instead of JOIN there would have been no confusion in mind and hence there was no need to have original question.
-
CreatedJul 16, 2013
-
UpdatedNov 03, 2020
-
Views2,223