MySQL sql 执行步骤

基本步骤是 
1.from 
2.join on 
3.where 
4.group by 
5.having 
6.order by 
7.select 
8.distinct ,sum,... 
9.limit 
 
join table 一定要有索引不然就是笛卡尔积了。
inner join 的特别
正确来讲 mysql 会先base on where 的过滤条件选出最好的table join table 方式 。 那么它是会先过滤掉 where 才开始join 的for 1st table .
不过我们通常是用 straight join 来控制它,以免我们不知道最后会是那个表被join出来 . 
having 是过滤掉 group by 之后的rows , 这时候的过滤可以使用count sum 那些,在where时候是不能使用的。
posted @ 2014-11-14 21:47  红尘客栈  阅读(200)  评论(0编辑  收藏  举报