WHERE clause before INNER JOIN

user1124535 picture user1124535 · Apr 13, 2012 · Viewed 34.6k times · Source

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?

Answer

Mosty Mostacho picture Mosty Mostacho · Apr 13, 2012

The where clause will be executed before the join so that it doesn't join unnecessary records. So your code is fine the way it is.