SQL Keywords

SQL INNER

What is SQL INNER JOIN?

INNER is used with JOIN to return rows that have matching values in both joined 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: PostgreSQL, MySQL, SQL Server, Oracle, SQLite, MariaDB, Snowflake, BigQuery, Redshift, DB2

SQL INNER Full Explanation

The INNER keyword appears directly before JOIN to create an INNER JOIN. An INNER JOIN combines rows from two or more tables based on a comparison between specified columns. Only rows that meet the join condition in every referenced table are included in the result set. If no match exists, the row is excluded. Because it filters out non-matching records, INNER JOIN is the most common join type for enforcing relational integrity in reporting and analytics.Key points:- INNER must be paired with JOIN; it cannot stand alone.- If JOIN is written without a preceding keyword, most dialects default to INNER JOIN.- The join condition is supplied after the ON or USING clause.- Multiple INNER JOINs can be chained to combine several tables.- Performance depends on indexed join columns; missing indexes can lead to slow queries.- NULL values only match other NULLs when using the ANSI SQL IS NOT DISTINCT FROM construct. Otherwise, NULL never equals NULL, so those rows are excluded.

SQL INNER Syntax

SELECT <columns>
FROM table_a
INNER JOIN table_b ON table_a.key = table_b.key;

SQL INNER Parameters

Example Queries Using SQL INNER

-- Basic two-table join
SELECT o.order_id,
       o.customer_id,
       c.customer_name
FROM   orders o
INNER JOIN customers c
       ON o.customer_id = c.id;

-- Chaining three INNER JOINs
SELECT p.product_name,
       c.category_name,
       s.supplier_name
FROM   products p
INNER JOIN categories c ON p.category_id = c.id
INNER JOIN suppliers  s ON p.supplier_id  = s.id;

-- Using table aliases and WHERE filter
SELECT e.employee_id,
       e.first_name,
       d.department_name
FROM   employees e
INNER JOIN departments d ON d.id = e.department_id
WHERE  d.location = 'Boston';

Expected Output Using SQL INNER

  • Result sets include only rows where the join condition evaluates to TRUE for all joined tables
  • Non-matching rows are discarded

Use Cases with SQL INNER

  • Retrieve related data from two or more tables where referential integrity is required
  • Build dimension-fact joins in star schemas
  • Enforce business rules that exclude orphan records
  • Replace subqueries for better readability and performance

Common Mistakes with SQL INNER

  • Omitting the ON clause and triggering a Cartesian product
  • Expecting NULL = NULL to match without using IS NOT DISTINCT FROM or COALESCE logic
  • Forgetting to index join columns, causing slow execution
  • Using INNER JOIN when LEFT JOIN is needed to keep unmatched left-table rows

Related Topics

JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, CROSS JOIN, USING clause, NATURAL JOIN

First Introduced In

SQL-92

Frequently Asked Questions

What is the difference between JOIN and INNER JOIN?

Writing JOIN by itself defaults to INNER JOIN, so both produce the same result set.

Why are some rows missing after an INNER JOIN?

Rows are returned only when the join condition matches in every table. If no match exists, the row is excluded. Use LEFT JOIN if you need unmatched rows from the left table.

How can I improve INNER JOIN performance?

Index the columns used in the join condition, avoid functions on join columns, and limit the result set with selective WHERE clauses.

Does INNER JOIN handle NULL values?

NULL never equals NULL in ANSI SQL, so rows with NULL in the join columns are filtered out unless you explicitly handle them with IS NOT DISTINCT FROM or COALESCE.

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!