Please give the order of execution of the sql query operators or give a link where to read about it: what is being done. For example (from the ceiling):

SELECT t1.id AS id, t1.name AS name, count(*) AS cnt FROM tbl_name1 t1 INNER JOIN tbl_name2 t2 ON t1.id = t2.id WHERE t1.id > 10 GROUP BY t1.name HAVING cnt > 10 ORDER BY t1.id 

First GROUP BY , then? The latest ORDER BY ... Nowhere can I find normal information about this: ((

    4 answers 4

    The order of execution of sentences in the select statement

    • but about JOIN there is not a word! :) or is it equivalent to FROM? if so before FROM or after? :) - FoxManiac pm
    • And, probably the internal optimizer reduces everything to the WHERE clause? What do you think, colleagues? - FoxManiac
    • one
      The join of tables (JOIN) is in the FROM clause and only there. - msi
    • those. JOIN is not a separate statement, but as part of the FROM clause? - FoxManiac
    • one
      Yes. FROM lists the tables used in the query. Starting with the SQL-92 standard, explicit join operations (i.e. JOIN) can be used there. Before that, join conditions were specified in the WHERE clause. - msi

    For SQL Server, see link .

    The logical order of processing a SELECT statement:

    1. FROM
    2. ON
    3. JOIN
    4. where
    5. GROUP BY
    6. WITH CUBE or WITH ROLLUP
    7. HAVING
    8. SELECT
    9. Distinct
    10. ORDER BY
    11. TOP

      The order of execution depends on the situation and is determined before the execution of the request. DBMSs allow you to view the execution plan - this is how the DBMS decided to execute the query.

         SELECT [DISTINCT | DISTINCTROW | ALL] select_expression,... [FROM table_references] [WHERE where_definition] [GROUP BY {unsigned_integer | col_name | formula} [ASC | DESC], ...] [HAVING where_definition] [ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC], ...] 
        • 3
          This is the syntax, and the parsing order is different from the syntactic order, for example, the select clause is executed almost at the very end, before the order by. That is why the aliases given to the columns are not visible, say, in the where clause. - msi