Post

MySQL中SQL语句执行顺序

一条SQL语句可分为以下几个类型:

  • Data Query Language (DQL) : 如 SELECT
  • Data Manipulation Language (DML) : 如 INSERT, UPDATE, DELETE
  • Data Definition Language (DDL) : 如 CREATE TABLE, ALTER TABLE, DROP TABLE
  • Data Control Language (DCL) : 如 GRANT, REVOKE, DENY

本文针对DQL的执行过程以及涉及的相关原理做了介绍。

数据查询语言最为常用,常见的查询语句为:

1
2
3
4
5
6
7
8
9
SELECT column_a,column_b
FROM t1
JOIN t2
    ON t1.column_a = t2.column_a
WHERE constraint_expression
GROUP BY column
    HAVING constraint_expression
ORDER BY column DESC
LIMIT count;

其查询命令的执行顺序如下图所示:

图片来源:Visualizing a SQL Query

This post is licensed under CC BY 4.0 by the author.