So, I've been seeing a lot of SQL examples on this site. I have a question about the relative performance of inner joins (plain JOIN
) and cross joins (SELECT foo FROM bar,baz WHERE
). Turns out the question has already been asked:
http://stackoverflow.com/questions/1018822/inner-join-versus-where-clause-any-difference
But I still have an issue I'd like clarification on. I didn't see anything in the answers.
The questions is this:
Assume no fields are NULL. Given two equivalent queries, one formulated like this:
SELECT * FROM t1
JOIN t2 ON t1.t2_id=t2.t1_id AND t2.bar='baz'
WHERE t1.foo='bar'
And one formatted like this:
SELECT * FROM t1,t2
WHERE t1.foo='bar' AND t1.t2_id=t2.t1_id AND t2.bar='baz'
Is there a difference in their execution time? I'm interested specifically in the case where restrictions are placed on values located in both tables, in addition to the ID-matching to associate like rows. Note that there is no foreign key constraint in this schema.
I should probably also say that I'm interested in how this extends to more than two tables.
Thanks in advance for your answers, SQL experts!