当前位置:网站首页>Zero foundation self-study SQL course | syntax sequence and execution sequence of SQL statements
Zero foundation self-study SQL course | syntax sequence and execution sequence of SQL statements
2022-06-24 09:14:00 【Meow Ningyi】
Hello everyone , I'm Ning Yi .
Today's talk SQL Course No 17 course :SQL Statement writing order and execution order .
SQL The writing order of statements is not consistent with the execution order , Let's make it clear through this lesson .
1、 Writing order
The order in which statements are written is important , If the order is wrong, it will be reported as wrong .
We have learned from the previous course SELECT、WHERE、ORDER BY、LIMIT、JOIN、UNION、GROUP BY、HAVING Sentence usage .
If these statements SQL At the same time , The writing order is like this :
SELECT < Field name >
FROM < Table name >
JOIN < Table name >
ON < Connection condition >
WHERE < filter >
GROUP BY < Field name >
HAVING < filter >
UNION
ORDER BY < Field name >
LIMIT < Limit the number of rows >;Looks complicated , But we don't have to memorize it , Do more practice , It's natural to remember .
2、 Execution order
1.FORM: choice from Following table , Generate virtual tables 1.
2.ON:ON yes JOIN The connection condition of , Rows that meet the join criteria are recorded in the virtual table 2 in .
3.JOIN: If you specify LEFT JOIN, The unmatched rows in the reserved table will be added to the virtual table as external rows 2 in , Generate virtual tables 3. If there are more than one JOIN link , Will repeat step 1~3, Until all tables are processed .
4.WHERE: For virtual tables 3 Conduct WHERE filter , Qualified records will be inserted into the virtual table 4 in .
5.GROUP BY: according to GROUP BY Column in clause , For virtual tables 2 Group the records in , Generate virtual tables 5.
6.HAVING: For virtual tables 5 Conduct HAVING Filter , Qualified records will be inserted into the virtual table 6 in .
7.SELECT:SELECT Do not execute until the next step , Select the specified column , Insert into virtual table 7 in .
8.UNION:UNION Two connected SELECT Query statement , Will repeat step 1~7, Generate two virtual tables 7,UNION These records will be merged into the virtual table 8 in .
9.ORDER BY: Put the virtual table 8 Sort the records in , Virtual table 9.
10.LIMIT: Take out the record of the specified line , Return result set .
3、 summary :
Writing order :SELECT -> FROM -> JOIN -> ON -> WHERE -> GROUP BY -> HAVING -> UNION -> ORDER BY ->LIMIT
Execution order :FROM -> ON -> JOIN -> WHERE -> GROUP BY -> HAVING -> SELECT -> UNION -> ORDER BY ->LIMIT
4、 What to pay attention to :
1.SELECT Statements are always written at the beginning , But execute after most statements . So in SQL In the sentence , We can't WHERE、GROUP BY、 HAVING Statement used in SELECT Alias set in .
however MYSQL There is a characteristic , stay GROUP BY、 HAVING In the sentence , have access to SELECT Alias set in . It's not because MYSQL Will be implemented in advance SELECT, It's because GROUP BY This step returns the cursor , Just have a look at it .
2. Whatever the writing order , Or execution sequence ,UNION Are all in line ORDER BY Ahead .SQL Statement will put all UNION After segment merging , And sort it out .
We have summarized in this lesson sql The order in which statements are written and executed , It helps us to understand these sql Statement optimization , Improve our database understanding . Build our back to write complex SQL The basis of .
If you can master it SQL Statement writing order and execution order , So congratulations , It can solve most of the problems SQL Problem. .
In the next class, we will start to talk about subquery , I understand the content of this lesson , Write more complex later SQL It's handy ~
Click on Focus on , Update the course and notify the first time ~
边栏推荐
- YOLOX backbone——CSPDarknet的实现
- Qingcloud based "real estate integration" cloud solution
- The native applet uses canvas to make posters, which are scaled to the same scale. It is similar to the uniapp, but the writing method is a little different
- Opencv maximum filtering (not limited to images)
- 支持向量机(SVC,NuSVC,LinearSVC)
- Time Series Data Augmentation for Deep Learning: A Survey 之论文阅读
- 深入了解 border
- Data midrange: detailed explanation of the technical stack of data acquisition and extraction
- [quantitative investment] discrete Fourier transform to calculate array period
- leetcode——错误的集合
猜你喜欢

Support vector machine (SVC, nusvc, linearsvc)

YOLOX backbone——CSPDarknet的实现

Webrtc series - network transmission 5: select the optimal connection switching

普通人没有学历,自学编程可以月入过万吗?

Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection

Opencv maximum filtering (not limited to images)

“论解不了数独所以选择做个数独游戏这件事”

EasyExcel单sheet页与多sheet页写出

活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中

【LeetCode】387. First unique character in string
随机推荐
牛客网 实现简单计算器功能
MYCAT read / write separation and MySQL master-slave synchronization
[quantitative investment] discrete Fourier transform to calculate array period
[redis implements seckill business ①] seckill process overview | basic business implementation
Get post: do you really know the difference between requests??????
Idea another line shortcut
学习太极创客 — ESP8226 (十三)OTA
1704. judge whether the two halves of a string are similar
Depens:*** but it is not going to be installed
关于 GIN 的路由树
零基础自学SQL课程 | 子查询
Jincang KFS replicator installation (oracle-kes)
Data middle office: a collection of middle office construction architectures of large domestic factories
2138. splitting a string into groups of length k
Lu Qi: I am most optimistic about these four major technology trends
eBanb B1手环刷固件异常中断处理
RISC-V架构下 FPU Context 的动态保存和恢复
2022.06.23 (traversal of lc_144,94145\
The border problem after the focus of input
[noi Simulation Competition] send (tree DP)