SQL INNER JOIN

What is SQL Inner Join

The inner join can be used to combine the column values of two tables based on the join conditions. The query created by using the inner join find all the rows match between the column of both the tables.

SQL INNER JOIN statement to combine two tables

In the above image, there are two table in which there are some matching rows. These matching rows gives the ouput table after using the JOIN statement. The filled color in the above image showing the output rows of the two tables.

Why You Should Use Inner Join in SQL Query

To combine two or more table, you can use the JOIN statement. Find the common rows of two tables and get the output in the new table created after the JOIN statement.

The inner join is the frequently used join in SQL query to join two or more tables.

How to Use SQL Inner Join to Combine Tables

To use the SQL inner join statement, you can use two tables. The first table is the main table that you have to use in the FROM. The second table is the table that you want to join with the main table or first table and use after JOIN.

Syntax

The third thing to do is to add the two tables by equating with the matching column name after the ON statement. To understand how to use the Join statement, you have to read further and check the below-given example.

However, you can use multiple tables with the JOIN statement. To get better performance of the query, you should limit the number of tables.

Example to Combine Two Tables Using SQL Inner Join Statement

To create a join statement in SQL, you have to use the SELECT statement. The select statement to join table creates a table with one or more columns from the two tables that you have specified.

Below are the two tables contain the column with one column matching rows.

SQL Inner Join Example Using the Select Statement

Table 1: Purchaser

Purchaser_ID Purchaser_Name Plot_No Service_Id
1 Sam 12 1001
2 Pill 13 1002
3 Don 14 1003
4 Brock 15 1004

Table 2: Seller

Id Seller_Name Seller_Email
1001 Big Show [email protected]
1002 Gem [email protected]
1003 Matt [email protected]

Now, let’s combine the above two tables using the example given below.

Example

Output

Service_Id Seller_Name Purchaser_Name Plot_No
1001 Big Show Sam 12
1002 Gem Pill 13
1003 Matt Don 14

Reference
Join Syntax