Saltar al contenido
uencoder

SQL JOIN Referencia

Referencia para SQL unir tipos: inner, izquierda, derecha, lleno, cross, natural, y self joins.

Join Types

INNER JOIN returns matching rows from both tables. LEFT (OUTER) JOIN returns all left rows plus matches (NULL for non-matches). RIGHT JOIN is the mirror of LEFT. FULL OUTER JOIN returns all rows from both, matching where possible. CROSS JOIN produces Cartesian product (every left x every right). NATURAL JOIN matches on same-named columns (risky, avoid). SELF JOIN joins a table to itself with aliases. Most joins use ON clause; USING matches same-named columns.

INNER
Matching only
intersection
LEFT
All left + matches
NULL for gaps
CROSS
Cartesian product
every combination

Join Performance

Join order affects performance; the query optimizer chooses based on statistics. Hash joins are efficient for large unsorted inputs. Merge joins require sorted inputs but are fast. Nested loop joins suit small outer tables. Indexes on join columns dramatically improve performance. Joining too many tables creates exponential plan search space. Denormalization reduces joins at the cost of redundancy. Modern databases use hash join for most equijoins. EXPLAIN reveals the chosen join strategy.

hash join
Large unsorted
build + probe
merge join
Sorted inputs
parallelizable
indexes
Join columns
critical for perf

Herramientas relacionadas

参考链接