好比有以下的sql查询语句,其中的执行顺序是什么样子的呢?sql
select * from help_topic as t join help_relation as r on t.help_topic_id = r.help_topic_id where t.help_topic_id < 200 having r.help_topic_id<150 order by t.help_topic_id asc;
简单来讲,上述语句是咱们所写的SQL语句,这个是人理解的顺序,固然对于初学者,这个顺序是有点绕的,机器执行的顺序和咱们手写SQL的顺序是不一致的!其执行顺序以下:code
1. FROM <left_table> 2. ON <join_codition> 3. <join_type> JOIN <right_table> 4. WHERE <where_condition> 5. GROUP BY <group_by_list> 6. HAVING <HAVING_condition> 7. SELECT 8. DISTINCT <select_list> 9. ORDER BY <order_by_condition> 10. LIMIT <limit_number>
整体来讲,MYSQL的查询语句,能够分为三个部分: 整体来讲,MYSQL的查询语句,能够分为三个部分:blog
select * from help_topic as t join help_relation as r on t.help_topic_id = r.help_topic_id;
select * from help_topic as t join help_relation as r on t.help_topic_id = r.help_topic_id where t.help_topic_id < 200;
select * from help_topic as t join help_relation as r on t.help_topic_id = r.help_topic_id where t.help_topic_id < 200 having r.help_topic_id < 150 order by t.help_topic_id asc;
正如上述描述,SQL查询就能够分红这么三个步骤。形象的解释以下图所示: it