一、Mysql 语法顺序
select[distinct]  
from  
join(如left joinon  
where  
group by  
having  
union  
order by  
limit
二、Mysql执行顺序
from  
on  
join  
where  
group by  
having  
select  
distinct  
union  
order by  

注:

1)使用distinct要写在所有要查询字段的前面,后面有几个字段,就代表修饰几个字段,而不是紧随distinct的字段;

2)group by执行后(有聚合函数),group by后面的字段在结果中一定是唯一的,也就不需要针对这个字段用distinct;

参考:https://blog.csdn.net/jintao_ma/article/details/51253356

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐