当前位置:网站首页>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 ~
边栏推荐
- Ebanb B1 Bracelet brush firmware abnormal interrupt handling
- PM2 deploy nuxt3 JS project
- 当程序员被问会不会修电脑时… | 每日趣闻
- Data midrange: analysis of full stack technical architecture of data midrange, with industry solutions
- Unable to change the virtual machine power status and report an error solution
- Every (), map (), forearch () methods. There are objects in the array
- tcpdump抓包实现过程
- MySQL | store notes of Master Kong MySQL from introduction to advanced
- 牛客网 实现简单计算器功能
- threejs辉光通道01(UnrealBloomPass && layers)
猜你喜欢

Huawei Router: IPSec Technology

Remote connection of raspberry pie without display by VNC viewer

EasyExcel单sheet页与多sheet页写出

CF566E-Restoring Map【bitset】

Qingcloud based "real estate integration" cloud solution

Mba-day25 best value problem - application problem

uniapp 开发多端项目如何配置环境变量以及区分环境打包

Yolox backbone -- implementation of cspparknet
![[e325: attention] VIM editing error](/img/58/1207dec27b3df7dde19d03e9195a53.png)
[e325: attention] VIM editing error

【gdb调试工具】| 如何在多线程、多进程以及正在运行的程序下调试
随机推荐
支持向量机(SVC,NuSVC,LinearSVC)
【Redis实现秒杀业务①】秒杀流程概述|基本业务实现
4274. suffix expression
Essay - Reflection
2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
【ES6闯关】Promise堪比原生的自定义封装(万字)
GradScaler MaxClipGradScaler
Cmake命令之target_compile_options
uniapp 开发多端项目如何配置环境变量以及区分环境打包
EasyExcel单sheet页与多sheet页写出
Scheme of alcohol concentration tester based on single chip microcomputer
Data middle office: middle office architecture and overview
Qingcloud based R & D cloud solution for geographic information enterprises
Get post: do you really know the difference between requests??????
Numpy numpy中的np.c_和np.r_详解
Linux (centos7.9) installation and deployment of MySQL Cluster 7.6
LeetCode之最长公共前缀
Some common pitfalls in getting started with jupyter:
Easyexcel single sheet and multi sheet writing
Time Series Data Augmentation for Deep Learning: A Survey 之论文阅读