SqlServer中关联表on和where后条件是否生效

来源:互联网 发布:求解方程组最优化 编辑:程序博客网 时间:2024/06/01 10:05

环境:Sql Server2008.

inner join on后面跟的直接条件是有效的,同时and后面跟的条件也是有效的;

left/right join on后面跟的直接条件是有效的,但是and后面跟的条件无效的;

 left/right join on可以通过where添加过滤条件,where后的条件都是有效的.

SELECT top 2 testDtil.* FROM testMain right join testDtil on testMain.joinhm = testDtil.joinhm and 1=2 ;
SELECT top 2 testDtil.* FROM testMain right join testDtil on testMain.joinhm = testDtil.joinhm where 1=2 ;
SELECT top 2 testDtil.* FROM testMain left join testDtil on testMain.joinhm = testDtil.joinhm and 1=2 ;
SELECT top 2 testDtil.* FROM testMain left join testDtil on testMain.joinhm = testDtil.joinhm where 1=2 ;
SELECT top 2 testDtil.* FROM testMain inner join testDtil on testMain.joinhm = testDtil.joinhm and 1=2 ;
SELECT top 2 testDtil.* FROM testMain inner join testDtil on testMain.joinhm = testDtil.joinhm where 1=2 ;

                                

0 0