SQLite INNER JOIN

The SQLite INNER JOIN is a join where the values in the join columns are compared using an equals comparison operator. An inner join returns all rows from both tables that match the specified join condition.

Syntax

The SQLite INNER JOIN syntax is as follows:

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

Example

Table of students

student_id first_name last_name birthday address_id
1 Paul Smith 2002-10-14 100
2 Charlotte Jones 2003-05-18 101
3 Theodore Hernandez 2003-08-12 102
4 Susan Taylor 2004-07-24 NULL

Table of student_address

address_id city country
100 San Antonio US
101 San Jose US
102 Philadelphia US
103 Austin US
104 Boston US
105 Seattle US

In the following example, the query uses INNER JOIN between the students table and student_address. The condition of the select is that address_id has the same values in both tables. Students without an address will not appear in the query result.

SELECT s.*
FROM students s INNER JOIN student_address sa 
ON s.address_id = sa.address_id ;

Output

student_id first_name last_name birthday address_id
1 Paul Smith 2002-10-14 100
2 Charlotte Jones 2003-05-18 101
3 Theodore Hernandez 2003-08-12 102