简体   繁体   中英

ON clause condition versus WHERE clause condition WITH JOIN in mysql

How should we determine which conditions to place in ON clause and which of them to place in WHERE clause in a mysql query. And which of them execute faster?

Most of the time is the same thing as Mysql Query Optimizer does the internal optimization and joins are basically extra conditions. You can also benchmark or use EXPLAIN/DESCRIBE to see how the query is actually executed and what is the query execution plan .

They are not the same.

  • Use WHERE clause to FILTER records.
  • Use JOIN...ON clause to query data from several tables or views; the ON keyword is used to BIND tables together. This clause is used when one-to-one, one-to-many or many-to-many relation is used.

As I know, when you are joining tables using WHERE clause, MySQL will join them with the general join algorithm. If you need to do LEFT JOIN , RIGHT JOIN or any other type of join, you need to define it explictly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM