SQL queries consist of a sequence of clauses. The diagram you have is rather misleading. Common clauses -- and the order they must appear for a valid query -- are:
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
Note that JOIN
is not a clause. It is an operator, and an operator that specifically appears only in the FROM
clause.
So, the answer to your question is that WHERE
clauses immediately follow the FROM
clause. The only "sort-of" exception is when a "window" clause is included and that is syntactically between the FROM
and the WHERE
.
Next, multiple table joins are often quite efficient and there is no reason whatsoever to discourage their use. Support for joins, in fact, is one of the key design features that databases are designed around.
And finally. What actually gets executed is not the string that you create. A query, in fact, describes the result set you want. It does not describe the processing. SQL is a descriptive language, not a procedural language.
The SQL engine has two steps to convert your query string to an executable form (typically a directed acyclic graph). One is to compile the query, and the second is to optimize the query. So, where filtering actually occurs . . . that depends on what the optimizer decides. And where it occurs has little relationship to what you think of when you think of SQL queries (DAGs don't generally have nodes called "select" or "join").
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…