MySQL 查询执行流程,SQL解析顺序

image

image

SQL示例:

SELECT DISTINCT
    < select_list >
FROM
    < left_table > < join_type >
JOIN < right_table > ON < join_condition >
WHERE
    < where_condition >
GROUP BY
    < group_by_list >
HAVING
    < having_condition >
ORDER BY
    < order_by_condition >
LIMIT < limit_number >

执行顺序:

FROM 
ON 
 JOIN 
WHERE 
GROUP BY 
HAVING 
SELECT 
DISTINCT 
ORDER BY 
LIMIT 

乍一看SQL的解析执行顺序还是让我有点儿出乎意料。但仔细看发现还是很合理的

从哪些表获取数据,这些表中数据通过哪个字段对应,检索什么样的数据,如何进行分组,过滤组,选择排重数据,然后再进行排序限制取几条。

你可能感兴趣的:(MySQL 查询执行流程,SQL解析顺序)