Posted: Sat Dec 29, 2007 5:55 pm
It's part of the INNER JOIN syntax: http://dev.mysql.com/doc/refman/5.0/en/join.html
The WHERE is part of the original SELECT
The WHERE is part of the original SELECT
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
So basically "ON table1.id = table2.id" will only select records where the id from one table equals the id from another? I could do the same with the WHERE clause, but I guess it's more clear this way. Is there any other usages for the ON clause?Kieran Huggins wrote:It's part of the INNER JOIN syntax: http://dev.mysql.com/doc/refman/5.0/en/join.html
The WHERE is part of the original SELECT
I believe that the ON selects records during the JOIN whereas WHERE would select records after the JOIN by scanning all the joined records. So ON is technically more efficient, but the way databases optimize queries these days that may or may not be actually true.JellyFish wrote:So basically "ON table1.id = table2.id" will only select records where the id from one table equals the id from another? I could do the same with the WHERE clause, but I guess it's more clear this way. Is there any other usages for the ON clause?
That totally makes sense.arborint wrote:I believe that the ON selects records during the JOIN whereas WHERE would select records after the JOIN by scanning all the joined records. So ON is technically more efficient, but the way databases optimize queries these days that may or may not be actually true.JellyFish wrote:So basically "ON table1.id = table2.id" will only select records where the id from one table equals the id from another? I could do the same with the WHERE clause, but I guess it's more clear this way. Is there any other usages for the ON clause?
Code: Select all
SELECT * FROM users INNER JOIN tags_users ON users.id = tags_users.user_id WHERE (tags_users.tag_id = tag.id AND tag.name IN $tag_list