SQL Keywords

SQL INNER JOIN

What is SQL INNER JOIN?

SQL INNER JOIN returns rows where the join condition matches in both tables.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL INNER JOIN: Supported by PostgreSQL, MySQL, SQL Server, Oracle, SQLite, MariaDB, Snowflake, BigQuery, Redshift, and most other relational databases.

SQL INNER JOIN Full Explanation

INNER JOIN is the most common type of table join in relational databases. It combines rows from two (or more) tables based on a comparison between columns, returning only those rows for which the join condition evaluates to TRUE. If no match exists between the tables, the row is excluded from the result set. Because INNER JOIN filters out non-matching rows, it is often used when you need an intersection of two datasets.Key points:- Order of tables does not affect the final result, but may impact execution plan and performance.- Multiple INNER JOINs can be chained to join three or more tables.- Join predicates typically use equality (equi-join) but can also use other comparison operators.- INNER JOIN can appear in the FROM clause together with table aliases for readability.- When columns share the same name, qualify them with table aliases to avoid ambiguity.Caveats:- Columns used in join conditions should be indexed to prevent expensive hash or nested-loop joins on large tables.- An accidental cartesian product can occur if the join condition is omitted or incorrect.

SQL INNER JOIN Syntax

SELECT column_list
FROM table1 [AS] t1
INNER JOIN table2 [AS] t2
  ON t1.column = t2.column;

SQL INNER JOIN Parameters

  • - table2 (table reference) - The table that will be joined to the first table.
  • - join_condition (boolean expression) - Expression that defines how rows from both tables relate. Usually an equality between key columns.

Example Queries Using SQL INNER JOIN

-- 1. Basic two-table join
SELECT o.id, o.order_date, c.name
FROM orders AS o
INNER JOIN customers AS c
  ON o.customer_id = c.id;

-- 2. Chain multiple INNER JOINs
SELECT p.name, c.name AS category, s.name AS supplier
FROM products AS p
INNER JOIN categories AS c ON p.category_id = c.id
INNER JOIN suppliers  AS s ON p.supplier_id  = s.id;

-- 3. INNER JOIN with additional filter
SELECT e.first_name, e.last_name, d.name AS department
FROM employees AS e
INNER JOIN departments AS d ON e.dept_id = d.id
WHERE d.location = 'NYC';

Expected Output Using SQL INNER JOIN

  • Each query returns a result set that includes only rows where the stated join conditions are satisfied
  • Non-matching rows from either table are excluded

Use Cases with SQL INNER JOIN

  • Retrieve related data that exists in both tables, such as orders that have customers or students that have enrollments.
  • Build dimension-fact joins in star schemas where you need only facts with valid dimensions.
  • Filter out orphaned records when cleaning data.
  • Combine multiple lookup tables to enrich a fact table in reporting queries.

Common Mistakes with SQL INNER JOIN

  • Forgetting the ON clause, which yields a cartesian product.
  • Using the WHERE clause instead of ON for join logic, which works but can reduce readability.
  • Joining on non-indexed columns, leading to slow queries.
  • Mixing up inner and outer joins when null-preserving behavior is required.

Related Topics

LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, NATURAL JOIN, JOIN USING, WHERE clause, ON clause

First Introduced In

SQL-92 standard

Frequently Asked Questions

What is the difference between INNER JOIN and OUTER JOIN?

INNER JOIN keeps only matching rows. OUTER JOIN (LEFT, RIGHT, FULL) preserves non-matching rows from one or both tables by filling missing columns with NULLs.

How many tables can I combine with INNER JOIN?

There is no hard limit in SQL standards. You can chain as many INNER JOIN clauses as needed, constrained only by database resource limits and performance.

Where should I put additional filters: ON or WHERE?

Join predicates belong in the ON clause. Row-level filters that are independent of the join belong in the WHERE clause. Keeping them separate improves clarity and can help query planners.

What happens if the join condition matches multiple rows in either table?

A composite result is produced for every matching combination. This can create duplicate business keys, so consider DISTINCT or aggregation if that behavior is unwanted.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!