SQL Inner Join Keyword | What is inner join in SQL with Example
In these articles, you will learn how to use the SQL INNER JOIN clause to query data from multiple tables,
The SQL Inner Join is the most commonly used Joins in SQL Server, The inner join SQL clause allows you to query data from two or more tables. The INNER JOIN SQL keyword selects records that have matching values in both tables and returns the records that have matching values in both or related multiple tables.

The SQL INNER JOIN selects all rows from both participating tables as long as there is a match between the columns. An INNER JOIN SQL is the same as the JOIN clause, combining rows from two or more tables.
The most frequently and important use of the joins is the INNER JOIN SQL. They are also referred to as an EQUIJOIN.
Syntax: SQL Inner Join
FROM table1 INNER JOIN table2
ON table1.column_name = table2.column_name;
OR
FROM table1
JOIN table2
ON table1.column_name = table2.column_name;
The following shows the syntax of SQL INNER JOIN clause the query retrieved data from both table1 and table2 tables:
furthermore, first, specify the main table (table1) in the FROM clause and second, specify the second table in the INNER JOIN SQL clause (table2) and a join predicate. Therefore, only rows that cause the join predicate to evaluate to TRUE are included in the result set.
The SQL INNER JOIN clause compares each row of the table (table1) with rows of the table (table2) to find them all pairs of rows that satisfy the join predicate. Furthermore, If the join predicate evaluates to TRUE, the column values of the matching rows of table1 and table2 are combined into a new row and included in the result set.
There are the given following table illustrates the inner join of two tables like table1 (A, B, C) and table2 (1,2,3). The result includes rows: (B,2) and (C,2) as they have the same color pattern patterns.

INNER JOIN between two tables
Therefore, let’s see the example of inner join in SQL between two tables, here we take two demo tables such as table1 for DoctorDetails and table2 for Department.
Let us first create a table DoctorDetails with the given below query.
|
1 2 3 4 5 6 |
CREATE TABLE DoctorDetails ( DoctorId int PRIMARY KEY, DoctorName VARCHAR(60) NOT NULL, FatherName VARCHAR(60) NOT NULL, HospitalId INT NOT NULL ) |
Demo Table :DoctorDetails
| DoctorId | DoctorName | FatherName | HospitalId |
|---|---|---|---|
| 101 | Aarav Adriano | Akim Alessio | 222 |
| 102 | Alexei Alvaro | Amedeo Andreas | 223 |
| 103 | Angus Ara | Aram Arjun | 224 |
| 104 | Armando Aurelio | Baptiste Bjorn | 222 |
| 105 | Bruno Cillian | Cormac Cosmo | 225 |
| 106 | Didier Dimitri | Dion Diango | 226 |
| 107 | Eduardo Eissa | Elio Fabiano | 224 |
| 108 | Fabrizio Florian | Fritz Fyodor | 227 |
| 109 | Gaston Guillaume | Gunnar Gwilym | 228 |
| 110 | Helio Janos | Joaquin kai | 226 |
| 111 | Adeline Anais | Adrienne Anastasie | 230 |
| 112 | Anne Marie Angelina | Augusta Catherine | 231 |
| 113 | Christine Claire | Charlotte Clarisse | 227 |
| 114 | Germaine Henriette | Hortense Louise | 232 |
| 115 | Lucienne Lucile | Janos Laszlo | 234 |
Therefore, let us create a Second table name as Department with the given below query.
|
1 2 3 4 5 6 |
CREATE TABLE Department ( HospitalId int PRIMARY KEY, HospitalName VARCHAR(60) NOT NULL, City VARCHAR(60) NOT NULL, Salary INT NOT NULL ) |
Demo Table: Department
| HospitalId | HospitalName | City | Salary |
|---|---|---|---|
| 222 | Apollo Hospitals | Mumbai | 45000 |
| 301 | Billroth Hospitals | Delhi | 42000 |
| 305 | Care Hospitals | Noida | 41000 |
| 225 | Council of Christian Hospitals | Kolkata | 45000 |
| 226 | Dr. Agarwal Eye Hospital | Chennai | 40000 |
| 311 | Command Hospital | Delhi | 48000 |
| 228 | Hinduja Healthcare Limited | Nagpur | 46000 |
| 307 | LifeSpring Hospitals | Hyderabad | 50000 |
| 309 | Vasan Healthcare | Jaipur | 41000 |
| 232 | LifeSpring Hospitals | Muradabad | 50000 |
| 233 | Wockhardt Hospitals | Agra | 47000 |
| 278 | Yashoda Hospitals | Sultanpur | 51000 |
| 235 | Sahyadri Hospital | Jhansi | 53000 |
| 236 | Regional Cancer Centre | Gorakhpur | 55000 |
| 237 | Sahyadri Hospital | Bangal | 54000 |
Furthermore, to join them Doctor Details Columns from DoctorDetails table and Hospital Name, hospital city, salary ID from the Department table, with the following condition:
1. HospitalId of DoctorDetails and Department table must be the same.
Therefore, there are the following SQL statement can be used :
SQL Code:
|
1 2 3 4 5 |
SELECT DoctorDetails.DoctorName,DoctorDetails.FatherName, Department.HospitalName,Department.City,Department.Salary FROM DoctorDetails INNER JOIN Department ON DoctorDetails.HospitalId =Department.HospitalId; |
SQL INNER JOIN using JOIN keyword
Therefore, let’s take an example SQL INNER JOIN using JOIN keywords, To get Doctor Name, doctor unit columns from DoctorDetails table and Hospital Name, city columns from Department table, after joining these mentioned tables, with the following condition –
1. the HospitalId of DoctorDetails and Department table must be the same.
the given below the following SQL statement can be used :
SQL Code:
|
1 2 3 4 5 |
SELECT DoctorDetails.DoctorName,DoctorDetails.FatherName, Department.HospitalName,Department.City,Department.Salary FROM DoctorDetails JOIN Department ON DoctorDetails.HospitalId =Department.HospitalId; |
INNER JOIN SQL for all columns
Therefore, to get all the columns from DoctorDetails and Department table after joining, with the following condition –
1. the HospitalId of DoctorDetails and Department table must be the same.
the given below the following SQL statement can be used :
SQL Code:
|
1 2 3 4 |
SELECT * FROM DoctorDetails JOIN Department ON DoctorDetails.HospitalId =Department.HospitalId; |
Difference between JOIN SQL and INNER JOIN
The SQL INNER JOIN selects all rows from both participating tables as long as there is a match between the columns.
Therefore, an SQL INNER JOIN is the same as the JOIN clause, the combining rows from two or more related tables.
JOIN SQL returns all rows from tables where the key record of one table is equal to the key records of another table.
Inner joins SQL use a comparison operator to match rows from two tables based on the values in common columns from each table. For example, retrieving all rows where the student identification number is the same for both the students and course tables.
furthermore, an inner join of X and Y gives the result of X intersect Y, i.e. the inner part of a Venn diagram intersection.

Syntax: When Using INNER JOIN Clause
|
1 2 3 |
SELECT * FROM table1 INNER JOIN table2 ON table1.column_name= table2.column_name; |
Syntax: Using JOIN Clause
|
1 2 3 |
SELECT * FROM table1 JOIN table2 ON table1.column_name=table2.column_name; |
WHERE clause vs INNER JOIN ON
| WHERE clause | INNER JOIN ON |
|---|---|
| The WHERE clause: what is done is that all data records that match the WHERE condition are included in the result set | Therefore, an INNER JOIN SQL is that data not matching the SQL JOIN condition is excluded from the result set. |
| Filtering on individual data elements should be done with the WHERE clause. | Linking between two or more related tables should be done using an INNER JOIN ON clause |
| The WHERE clause syntax is more relational model-oriented. | SQL INNER JOIN is an ANSI syntax |
| the result of two tables JOIN’ed can be filtered on matching the columns when using the WHERE clause. | The INNER JOIN is generally considered more readable and it is a cartesian product of the tables, especially when you join lots of tables |
Difference between INNER JOIN and OUTER JOIN
An INNER JOIN SQL is a type of join that returns all rows from both the participating tables, therefore, where the key record of the first table is equal to the key records of the second table. so, this type of join required a comparison operator to match rows from the participating tables based on a common field or column of both the related tables.
Whereas the OUTER JOIN SQL returns all rows from the participating tables which satisfy the condition and also those rows which do not match the condition will appear in this operation.
There are three types of OUTER JOIN SQL format:-
1: The LEFT OUTER JOIN SQL, in this join, includes all the rows from a left table of JOIN SQL clause and the unmatched rows from a right table with NULL values for selected columns.
2: The RIGHT OUTER JOIN SQL, in this join, includes all rows from the right of JOIN SQL cause and the unmatched rows from the left table with NULL values for selected columns.
3: The FULL OUTER JOIN SQL, in this join, includes the matching rows from the left and right tables of the JOIN clause and the unmatched rows from the left and the right table with NULL values for selected columns.
SQL INNER JOIN: Table Aliases make SQL Joins Easier to Read

SQL Code:
|
1 2 3 4 5 6 7 8 |
SELECT Store.ShopName, Store.City, CompanyLaptop.LaptopModelNumber FROM Store.Store INNER JOIN Store.CompanyLaptop ON Store.BusinessRegistrationID = CompanyLaptop.BusinessRegistrationID |
|
1 2 3 4 5 |
SELECT columnlist FROM maintable INNER JOIN secondtable ON join condition WHERE filter condition ORDER BY columnlist |
The WHERE clause refers to any of the fields from the joined tables. therefore, it is best practice to prefix the columns with the table name. The same goes for sorting. Use any field; however, it is common to sort by one or more related fields you are selecting. Let’s take our Laptop directory, but only list store, in order of the city, those whose city starts with D. therefore, With this requirement in your mind, our SQL statement becomes:
|
1 2 3 4 5 6 7 8 9 10 |
SELECT Store.ShopName, Store.City, CompanyLaptop.LaptopModelNumber FROM Store.Store INNER JOIN Store.CompanyLaptop ON Store.BusinessRegistrationID = CompanyLaptop.BusinessRegistrationID WHERE store.City LIKE 'D%' ORDER BY Store.City |
Important Notice: therefore, the join condition are remains the same but only changes are the addition of the WHERE and ORDER BY clauses. By now these should be familiar to you.