SQL – Inner Join (Simple Join)

Prev     Next

  • INNER JOIN in SQL is used to combine two or more tables together using the matching columns from both tables. All matching column records are selected. All selected columns from different tables are displayed in the single result table.
  • An inner join is also called as simple join which is used frequently in SQL for joining tables.
  • INNER JOIN in SQL is possible only when there is at least one common column available in those tables. And, we will get records from those tables when those 2 common column’s value is matched.

SQL Syntax for Inner Join (Simple Join):

SQL Syntax for Inner Join (Simple Join) SELECT table1.column1, table2.column2, etc
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
Or

Another Equivalent SQL Syntax for Inner Join (Simple Join)

SELECT table1.column1, table2.column2, etc
FROM table1
JOIN table2
ON table1.column_name = table2.column_name;

Please consider following 2 tables with few records as given below.

Table1:


Table name (for example): student1
Column names in this table: Student_ID, Student_name, City and Age
Available records: 4 rows

sql-table1

Table2:

Table name (for example): student2
Column names in this table: Student_ID, Department, College and Rank
Available records: 4 rows


sql-table40

Example: how to use SQL Inner Join (Simple Join):

SQL Query:

SELECT student1. Student_name, student1.City, student2. Department, student2.Rank
FROM student1
INNER JOIN student2
ON student1.Student_ID = student2.Student_ID;

Or

SELECT student1. Student_name, student1.City, student2. Department, student2.Rank
FROM student1
JOIN student2
ON student1.Student_ID = student2.Student_ID;

Description:

In above SQL INNER JOIN, 4 columns are selected from 2 different tables by joining common field ‘Student_ID’ from both tables.  There is only 3 matching ‘Student_ID’ are available in both tables. So, only 3 records are fetched and displayed as output.

RUN SQL

SQL query Output:

sql-table43

CONTINUE ON OTHER SQL JOINS:

Click on each SQL joins below for detailed description and example SQL queries.

Type of SQL JOINS Description
SQL – Inner Join (Simple Join) It is used to combine two or more tables together using the matching columns from both tables.
SQL – Left Join (Left outer join) LEFT JOIN selects all records from left table and also selects all matching records from the right table.
SQL – Right Join (Right outer join) RIGHT JOIN selects all records from right table and also selects all matching records from the left table.
SQL – Full Join (Full outer join) FULL JOIN selects and returns all records from both left and right tables.
SQL – Self Join Self Join is used to join a table to itself.
SQL – Cartesian Join or Cross Join Cartesian Join returns the Cartesian products of 2 or more tables joined together.

Prev     Next

Share this website !!!
Facebook Twitter Linkedin