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.
- 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.LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, NATURAL JOIN, JOIN USING, WHERE clause, ON clause
SQL-92 standard
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.
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.
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.
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.