Left Join 和 where 到底先执行哪个?

今天在review的时候,看到一个SQL文,是用Left Join来做的。

           Select * From a Left join b on a.c = b.c and  b.d = ? where a.d =?

当时 就觉得Left Join 的on中的条件,应该只有两张表的关系,而不应该涉及到单张表的过滤,还有认为where中的过滤先于join,但做了个试验,发现自己的想法错了。试验如下:

         1 Select * From a Left join b on a.c = b.c and  b.d = ? where a.d =?

         2 Select * From a Left join b on a.c = b.c where a.d =? and  b.d = ?

         上述两个SQL的检索件数不一样,这其实也证实了,先做Join 再做过滤

posted on 2008-09-25 16:44  stiffyan  阅读(4970)  评论(0)    收藏  举报

导航