MySQL的语句的执行顺序

我们编写的语句格式如下:

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 >

MySQL的执行顺序如下:

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

虽然,我们写的SELECT语句在前,但是在MySQL的执行顺序中,首先执行的FROM语句。
图形方式展示如下:
MySQL的执行顺序

posted @ 2020-09-05 17:12  houxin  阅读(168)  评论(0编辑  收藏  举报