Search code examples
mysqljoinoptimizationwhere-clause

WHERE clause before INNER JOIN


If I have

SELECT * FROM Table1 t1 
LEFT JOIN Table2 t2 ON t1.id = t2.id 
WHERE t1.user='bob';

Does the WHERE clause run after the two tables are JOINED?

How do I make it so it runs prior to the JOIN?


Solution

  • Change the WHERE to another JOIN condition

    LEFT JOIN Table2 t2 on t1.id = t2.id AND t1.user='bob'