SQLite Inner Join

Summary: This tutorial shows you how to use the SQLite inner join clause to query data from multiple tables.

Introduction to SQLite inner join clause

In relational databases, data is often distributed in many related tables. A table is associated with another table using foreign keys.

To query data from multiple tables, you use INNER JOIN clause. The INNER JOIN clause combines columns from correlated tables.

Suppose you have two tables: A and B.

A has a1, a2, and f columns. B has b1, b2, and f column. The A table links to the B table using a foreign key column named f.

The following illustrates the syntax of the inner join clause:

SELECT a1, a2, b1, b2
FROM A
INNER JOIN B on B.f = A.f;Code language: SQL (Structured Query Language) (sql)

For each row in the A table, the INNER JOIN clause compares the value of the f column with the value of the f column in the B table. If the value of the f column in the A table equals the value of the f column in the B table, it combines data from a1, a2, b1, b2, columns and includes this row in the result set.

In other words, the INNER JOIN clause returns rows from the A table that have the corresponding row in B table.

This logic is applied if you join more than 2 tables.

See the following example.