I know the followings queries return the same:
SELECT `cimgs`.*
FROM `cimgs`
INNER JOIN `cimgs_tags` ON `cimgs_tags`.`cimg_id` = `cimgs`.`id`
WHERE `cimgs_tags`.`tag_id` IN (1, 2, 3, 4, 5) AND (cimgs.id != 1)
SELECT `cimgs`.*
FROM `cimgs_tags`
INNER JOIN `cimgs` ON `cimgs`.`id` = `cimgs_tags`.`cimg_id`
WHERE `cimgs_tags`.`tag_id` IN (1, 2, 3, 4, 5) AND (cimgs.id != 1)
But, at a first glance I would say that the first one duplicates the cimgs table for each tag before checking the conditions, when the second one check the conditions and then it joins the corresponding tables…
Though I don’t know if MySQL detects and optimize this automatically and these two queries have a similar performance?
The query optimizer will do this for you. It will use the index statistics, which you should keep up to date with ANALYSE TABLE. You can force te join order using STRAIGHT_JOIN though, and you can force to use certain indexes, too.
You can do an explain:
to see the differences.
Offcourse, for a LEFT JOIN or RIGHT JOIN, there is a semantic difference.