MySQL的语句的执行顺序

2020-09-14  本文已影响0人  houxin

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

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的执行顺序
上一篇下一篇

猜你喜欢

热点阅读