日期:2014-05-18  浏览次数:20446 次

关于在join中的on后面用where和and的问题
SQL code
  select bl.LogMessage,bl.SystemDate,ncus.[user_name],bf.IsDelisting,bf.PName from B_PrjBaseInfo bf 
  join B_Log bl on bf.PID=bl.ProjectId
  join U_User us on us.UserID=bl.UserID
  join NCUserList ncus on ncus.[cuserid]=us.CuserID
  [color=#FF0000]where[/color] bl.LogType=3 and bf.IsDelisting=1

疑问上面的where换成and后运行结果一样。我想问一下它们在这条语句中应用的区别。谢谢!!!
是不是说明以后再用的过程中,不用考虑它们的问题了。??

SQL code
  select bl.LogMessage,bl.SystemDate,ncus.[user_name],bf.IsDelisting,bf.PName from B_PrjBaseInfo bf 
  join B_Log bl on bf.PID=bl.ProjectId
  join U_User us on us.UserID=bl.UserID
  join NCUserList ncus on ncus.[cuserid]=us.CuserID
  [color=#FF0000]and[/color] bl.LogType=3 and bf.IsDelisting=1



------解决方案--------------------
where换成and 执行速度会快一些

一个是将符合条件的数据直接联合起来,另一个选出全部数据再次筛选符合条件的
------解决方案--------------------
你这是内联接,所以where换成and,执行计划都是一样的。
如果是左右联接,那么where将在on后面执行,也就是on形成的结果集,再使用where来筛选,速度和结果集都不一样。
------解决方案--------------------
内联接,where和and的执行计划是一样的。
如果是左右联接,where在on后面执行,也就是对on形成的结果集再进行筛选,速度和效率是不一样的。
------解决方案--------------------
你这的join ...on 就相当于是inner join ....on 做连接操作
后面的where结果是一样的。如果你换为left join ...on 或者right....join .....on 
那where后面就不一样了。