The execution order of WHERE and ON clauses is: 1. The WHERE clause is executed first and rows that meet the conditions are filtered out. 2. The ON clause is then applied to the filtered rows, establishing a join based on the join conditions.
Execution order of WHERE and ON clauses in SQL
In SQL query, WHERE and ON clauses is an important structure for filtering data sets. Understanding the order in which these two clauses are executed is critical to optimizing query performance.
Execution order:
The WHERE clause is executed before the ON clause.
Detailed explanation:
Example:
<code class="sql">SELECT * FROM table1 WHERE column1 = 'value1' INNER JOIN table2 ON table1.column2 = table2.column3;</code>
In this query, the WHERE clause first filters out column1
in table1
Rows equal to value1
. The ON clause then joins table1
and table2
if table1.column2
is equal to table2.column3
. Only rows that satisfy both the WHERE and ON conditions will be returned.
The importance of understanding the order of execution:
The above is the detailed content of In sql, which one is executed first, where or on?. For more information, please follow other related articles on the PHP Chinese website!