INNER JOIN

BrandonDusch's avatar
Published May 7, 2021Updated Aug 18, 2022
Contribute to Docs

The INNER JOIN command returns all rows that have matching values in both tables and omits non-matching rows.

INNER JOIN GIF

Syntax

SELECT
  table_A.this_column,
  table_A.that_column,
  table_B.this_column,
  table_B.that_column,
FROM table_A
INNER JOIN table_B
  ON table_A.this_value = table_B.this_value;

One or more matching columns can be selected and joined from table_A and table_B based on matching column values between tables in the ON clause.

Example

The following example creates a result set of every row where the student_id matches in both tables and only includes last_name, first_name, and both GPAs:

SELECT
students.last_name,
students.first_name,
students.overall_gpa,
transfer_data.overal_gpa
FROM students
INNER JOIN transfer_data
ON students.student_id = transfer_data.student_id;

All contributors

Contribute to Docs

Learn SQL on Codecademy