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_IDPurchaser_NamePlot_NoService_Id
1Sam121001
2Pill131002
3Don141003
4Brock151004

Table 2: Seller

IdSeller_NameSeller_Email
1001Big Show[email protected]
1002Gem[email protected]
1003Matt[email protected]

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

Example

Output

Service_IdSeller_NamePurchaser_NamePlot_No
1001Big ShowSam12
1002GemPill13
1003MattDon14

Reference
Join Syntax

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.