Order of statement, Order of query

단단한어린이·2022년 4월 24일
0

Database

목록 보기
5/5
post-thumbnail

Order of writing

  • SELECT

  • FROM

  • WHERE

  • GROUP BY

  • HAVING

  • UNION

  • ORDER BY


Order of execution

  • FROM

  • WHERE

  • GROUP BY

  • HAVING

  • SELECT

  • UNION

  • ORDER BY


SQL will first choose where my table is selected, including the table's restrictions, (such as connection mode JOIN and restrictions ON)

SQL will choose what my judgment condition is, that is, the problem of WHERE

Then it will group by grouping and execute the HAVING statement.

SELECT statement is executed after most of the statements are executed, so we must understand that the statement executed in front of it will affect it, and pay attention to the actual work. This is especially important.

With the execution order of the statement we can find that order by the last execution, so we can sort the new fields named in select.


UNION Operator

The UNION operator is used to combine the result-set of two or more SELECT statements.
Every SELECT statement within UNION must have the same number of columns.
The columns must also have similar data types.
The columns in every SELECT statement must also be in the same order.

profile
Footprints in Coding

0개의 댓글