MySQL operation order?

Is there a final place to find the order of operations for mySQL statements? Is the order shown below correct?

Sentence

FROM WHERE clause GROUP BY clause HAVING clause SELECT clause ORDER BY clause

If so, can I use the term defined in the SELECT cluster (select first_name as "f_name") in the sentence group?

Thank!

+3
source share
2 answers

I assume that you are interested SELECT, according to the MySQL documentation, the syntax is as follows

SELECT
[ALL | DISTINCT | DISTINCTROW ]
  [HIGH_PRIORITY]
  [STRAIGHT_JOIN]
  [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
  [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
  [ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
  [ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' export_options
  | INTO DUMPFILE 'file_name'
  | INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]

Yes, you can use columns defined with help ASin a sentence GROUP BY.

+2
source

, Order By Select ( , ), Group By , , . , ( ). , , " ".

, , , MySQL, :

  • ( FROM, JOIN)
  • ()
  • ()
  • (SELECT)
  • (GROUP BY)
  • (HAVING)
-1

Source: https://habr.com/ru/post/1770999/


All Articles