mysql中的SQL语句执行的顺序

1. from
2. on
3. join
4. where
5. group by
6. with
7. having
8. select
9. distinct
10. order by
11. limit

 

例:

        select d1.*,
               d2.dept_name p_name,
               d2.dept_id p_id
           from dept_p d1
           left join dept_p d2
                on d1.parent_id = d2.dept_id

  

 

其中的最后一行中的  d2.dept_id   不能换为   d2.p_id

 

原因:

    先执行on,再执行select

 

posted @ 2019-05-08 10:26  小菜鸡的梦想  阅读(149)  评论(0编辑  收藏  举报