SQL JOIN Referenz
Referenz für SQL verbinden Typen: inner, links, rechts, voll, cross, natural, und 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
- LEFT
- All left + matches
- CROSS
- Cartesian product
intersection NULL for gaps 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
- merge join
- Sorted inputs
- indexes
- Join columns
build + probe parallelizable critical for perf