SQL Query

 Sun 12 January 2020   In 数据库   :)

  • SQL查询语句执行顺序
(7) SELECT

(8) DISTINCT

(1) FROM

(3) JOIN

(2) ON

(4) WHERE

(5) GROUP BY

(6) HAVING 


(9) ORDER BY

(10) LIMIT [, ] 

说明: HAVING类似WHERE,不同之处在于WHERE过滤行HAVING过滤组
  • MySQL中的SELECT语句文档:
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 
[PARTITION partition_list] 
[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' 
[CHARACTER SET charset_name] 
export_options 
| INTO DUMPFILE 'file_name' 
| INTO var_name [, var_name]] 
[FOR UPDATE | LOCK IN SHARE MODE]]