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

05-26 22:10