SQL INNER JOIN


The most frequently used and important of the joins is the INNER JOIN. They are also referred to as an EQUIJOIN.

The INNER JOIN creates a new result table by combining column values of two tables (table1 and table2) based upon the join-predicate. The query compares each row of table1 with each row of table2 to find all pairs of rows which satisfy the join-predicate. When the join-predicate is satisfied, column values for each matched pair of rows of A and B are combined into a result row.

Syntax

SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_field = table2.common_field;

Example

The Student table,

IDNAME
11Ashwani
12Sachin
13Deepak
14Soun

The student_info table,

IDAddress
11Delhi
12Haryana
13Punjab

Query

SELECT * FROM student, student_info WHERE student.id = student_info.id;
Output
IDNAMEIDAddress
11Ashwani11Delhi
12Sachin12Haryana
13Deepak13Punjab

Share this article on