Home > Database > SQL > What is the order of execution of sql statements?

What is the order of execution of sql statements?

coldplay.xixi
Release: 2023-01-13 00:40:50
Original
114035 people have browsed it

SQL statement execution order: 1. From tab is executed first; 2. Where statement limits the conditions; 3. Group statement [group by... having]; 4. Aggregation function; 5. Select statement ;6. Order by sorting statement.

What is the order of execution of sql statements?

The operating environment of this article: Windows 7 system, sql server 2019 version, Dell G3 computer.

sql statement execution sequence:

1. from

First determine which table to fetch data from, so from tab is executed first. There are multiple table connections from tab1, tab2. You can add aliases to the table to facilitate subsequent references.

What is the order of execution of sql statements?

2. Where

The where statement limits the condition. If there is no need to limit it, write where 1=1, which means it is always true. , no strings attached.

What is the order of execution of sql statements?

3. group by... having

Grouping statements, such as grouping by employee name, the field to be grouped must appear in the select, otherwise An error will be reported. Having is used in conjunction with group by to limit conditions. Here is an example.

What is the order of execution of sql statements?

4. Aggregation functions

Commonly used aggregation functions include max, min, count, and sum. Aggregation functions are executed after group by and before having. If you write an aggregate function in where, an error will occur.

What is the order of execution of sql statements?

5. Select statement

Select the field to be searched. If you select all, you can select *. Here select the employee name and total salary for all months.

What is the order of execution of sql statements?

6. Order by

sorting statement, the default is ascending order. If you want to sort in descending order, write order by [XX] desc. The order by statement is executed at the end, and sorting can only be performed if select selects the field to be found.

What is the order of execution of sql statements?

Recommended (free): sql tutorial

The above is the detailed content of What is the order of execution of sql statements?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template