当前位置:网站首页>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 ~
边栏推荐
- I heard that you are still spending money to buy ppt templates from the Internet?
- 【Redis实现秒杀业务①】秒杀流程概述|基本业务实现
- Support vector machine (SVC, nusvc, linearsvc)
- Easyexcel single sheet and multi sheet writing
- CF566E-Restoring Map【bitset】
- linux(centos7.9)安装部署mysql-cluster 7.6
- On the routing tree of gin
- Target detection series fast r-cnn
- What do you mean by waiting for insurance records? Where should I go for filing?
- 陆奇:我现在最看好这四大技术趋势
猜你喜欢

Linux MySQL installation

Leetcode -- wrong set

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

Data middle office: detailed explanation of technical architecture of data middle office

A tip to read on Medium for free

玄铁E906移植----番外0:玄铁C906仿真环境搭建

MySQL | view notes on Master Kong MySQL from introduction to advanced

陆奇:我现在最看好这四大技术趋势

小白学习MySQL - 增量统计SQL的需求

eBanb B1手环刷固件异常中断处理
随机推荐
Xiaobai needs to learn MySQL - incremental statistical SQL
LeetCode之最长公共前缀
Time Series Data Augmentation for Deep Learning: A Survey 之论文阅读
Unable to change the virtual machine power status and report an error solution
Support vector machine (SVC, nusvc, linearsvc)
"I can't understand Sudoku, so I choose to play Sudoku."
2020 China's provinces and cities, three-level linkage data, data agencies (data from the official website of the National Bureau of Statistics)
十二、所有功能实现效果演示
PM2 deploy nuxt3 JS project
I heard that you are still spending money to buy ppt templates from the Internet?
每周推荐短视频:计算的终极形态是“元宇宙”?
Recommendation - Secret of curiosity: how many dancing angels can stand on the tip of a needle?
threejs辉光通道01(UnrealBloomPass && layers)
Yolox backbone -- implementation of cspparknet
How to configure environment variables and distinguish environment packaging for multi terminal project of uniapp development
Pytoch read data set (two modes: typical data set and user-defined data set)
软件系统依赖关系分析
MYCAT read / write separation and MySQL master-slave synchronization
Qingcloud based R & D cloud solution for geographic information enterprises
关于 GIN 的路由树