🗄️ SQL examples

INNER JOIN Examples in SQL

Return rows that match in both tables. This page gives you the syntax, five practical examples, common mistakes, and copy-ready SQL you can adapt.

Updated 2026-06-125 practical examplesCopy-ready SQL

What INNER JOIN does

Return rows that match in both tables. SQL syntax can vary by database, but the pattern below is a useful starting point for reports and analysis.

Syntax or pattern

SELECT * FROM orders o INNER JOIN customers c ON o.customer_id = c.customer_id;
✍️

5 practical examples

1

Orders with customer details

Return only orders with a matching customer.

SELECT o.order_id, c.email, o.total_amount FROM orders o INNER JOIN customers c ON o.customer_id = c.customer_id;

INNER JOIN keeps matched rows only.

2

Order lines with product names

Add product names to order line items.

SELECT oi.order_id, p.product_name, oi.quantity FROM order_items oi INNER JOIN products p ON oi.product_id = p.product_id;

This is common for invoice and sales line reports.

3

Tickets with assigned agents

Show tickets that have an agent record.

SELECT t.ticket_id, a.agent_name FROM tickets t INNER JOIN agents a ON t.agent_id = a.agent_id;

Unassigned tickets will not appear with an inner join.

4

Sales with region lookup

Add region names from a reference table.

SELECT s.sale_id, r.region_name, s.amount FROM sales s INNER JOIN regions r ON s.region_id = r.region_id;

Reference joins enrich fact tables for reporting.

5

Check matching keys

Start with a count before joining more tables.

SELECT COUNT(*) FROM orders o INNER JOIN customers c ON o.customer_id = c.customer_id;

Counting joined rows helps catch key issues early.

Common mistakes to avoid

  • Forgetting that SQL dialects vary across PostgreSQL, SQL Server, MySQL, BigQuery and SQLite.
  • Using SELECT * in production reports when only a few columns are needed.
  • Not checking join keys, duplicate rows or NULL values before trusting results.

FAQ

Will this SQL work in every database?

The idea is portable, but function names and date syntax may vary. Check your database dialect if a function is not recognized.

Should I use this in a report query?

Yes, if the pattern matches the business question and you have checked filters, joins and row counts.

Why does my result have too many rows?

The most common reasons are duplicate join keys, missing filters or grouping at the wrong level of detail.

💡 Useful resources

Here are some ideas for you

Optional resources that may help if you are learning SQL, building reports, writing queries or improving your data workflow.

  • 📘
    SQL books for beginners

    Practice query patterns with structured examples and exercises.

    See ideas
  • 🧱
    Database design books

    Understand tables, keys, relationships and why joins behave the way they do.

    See ideas
  • ⌨️
    Mechanical keyboards

    Useful if you write queries, code and documentation for long work sessions.

    See ideas
  • 🖥️
    External monitors

    View query editor, result grid and documentation side by side.

    See ideas
  • 📒
    Developer notebooks

    Sketch table relationships, query logic and report ideas before coding.

    See ideas
  • 💡
    Desk lamps

    Keep your workspace comfortable while studying or debugging queries.

    See ideas

Some links in this section may be affiliate links. Choose only what is useful for your own work.