您的位置:首页 > 数据库

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

2015-08-29 13:31 423 查看
环境: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 ;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: