在INNER JOIN之前如何执行WHERE子句 [英] How to do WHERE clause BEFORE INNER JOIN

查看:475
本文介绍了在INNER JOIN之前如何执行WHERE子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何查询?

select Distinct  Station  , Slot , SubSlot, CompID , CompName 
from DeviceTrace as DT DT.DeviceID = '1339759958' 
inner join CompList as CL  
where  and DT.CompID = CL.CompID

我需要做DT.DeviceID = '1339759958',然后再开始进行内部联接. 我使用sql server.

I need to do DT.DeviceID = '1339759958' before I start with the inner join. I work with sql server.

推荐答案

我很难相信它会带来任何改变.如果查询优化器计算出谓词效率更高,则应在连接之前应用谓词.唯一可能需要执行此操作的情况是,当优化程序做出错误选择时(至少对于内部联接而言-存在外部联接的有效情况).

I find it difficult to believe that it makes any difference. The query optimiser should apply the predicate before the join if it calculates that it is more efficient to do so. The only circumstance where you might need to do this is when the optimiser makes an erroneous choice (for inner joins at least -- there are valid cases for outer joins).

这篇关于在INNER JOIN之前如何执行WHERE子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆