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
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.
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.
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.
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.
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.