where子句与内部join语句检查是否相同? [英] Where clause versus inner join statement checks, are they the same?

查看:71
本文介绍了where子句与内部join语句检查是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在JOIN或WHERE中的条件

以下两个查询是否相同?

Are the below 2 queries the same?

SELECT u.*
FROM User u
    INNER JOIN Sales s ON (u.userId = s.userId)
WHERE
u.active = 1 AND
s.amount > 0 AND
s.status = 1 

与之相对:

SELECT u.*
FROM User u
    INNER JOIN Sales s ON 
        (u.userId = s.userId AND s.amount > 0 and s.status=1)
WHERE
u.active = 1

这两个查询在结果集方面是否始终相同?性能方面的考虑因素?

Are these 2 queries the same in terms of result set always? Performance considerations?

推荐答案

SQL Server查询优化器足够聪明,可以理解这将执行相同的操作,因此他将生成相同的执行计划.这意味着您将获得相同的性能.为了确保您可以查看执行计划并进行比较.

The SQL Server Query Optimizer is smart enough to understand that this will do the same, so he will generate the same execution plan. That means you will get the same performance. To make it sure you can look at the Execution plan and compare them.

查看执行计划基础

这篇关于where子句与内部join语句检查是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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