SQL JOINs in MySQL
Definition
MySQL implements all standard SQL JOIN types with its own optimizer that uses hash joins, block nested loop joins, and index-based nested loops for performance.
Introduction to SQL JOINs in MySQL
MySQL 8.0 introduced hash join support, dramatically improving performance for large JOIN operations that lack usable indexes. Understanding MySQL's join execution strategies and available optimizer hints lets you write joins that scale to millions of rows.
Syntax
-- Standard JOIN syntax SELECT t1.col, t2.col FROM table1 t1 JOIN table2 t2 ON t1.id = t2.t1_id; -- STRAIGHT_JOIN: forces left table to be read first SELECT STRAIGHT_JOIN e.name, d.name FROM employees e JOIN departments d ON e.dept_id = d.id;
Examples
MySQL 8.0 Hash Join
-- MySQL 8.0+ uses hash join automatically when no indexes exist -- Force hash join with optimizer hint: SELECT /*+ HASH_JOIN(o, c) */ o.id, c.name FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.total > 1000;
MySQL 8.0 introduced hash joins. The optimizer chooses the best strategy, but you can hint with /*+ HASH_JOIN() */ for specific scenarios.
Try in PlaygroundLEFT JOIN to Find Non-Matching Records
-- Find customers who have never placed an order SELECT c.id, c.name, c.email FROM customers c LEFT JOIN orders o ON c.id = o.customer_id WHERE o.id IS NULL;
LEFT JOIN + WHERE IS NULL is the standard SQL pattern for anti-join — finding rows in the left table that have no match in the right table.
Try in PlaygroundCommon Mistakes
MySQL does not support FULL OUTER JOIN natively — simulate with LEFT JOIN UNION RIGHT JOIN
Joining on columns with different charsets/collations — disables indexes and causes implicit conversion
Not having an index on the JOIN column in the right-hand (inner) table — massive performance impact
Using USING() with ambiguous column names in complex queries
Frequently Asked Questions
Does MySQL support FULL OUTER JOIN?
What is STRAIGHT_JOIN in MySQL?
What join algorithms does MySQL 8 use?
Related SQL Topics
Practice This in the SQL Playground
Write real queries, see live results, and master SQL JOINs in MySQL hands-on. 100% free.