1
假设我们有两个表与查询性能并没有加入
客户和订单
客户表: -
custid custname
------- ---------
1 aaa
2 bbb
3 ccc
订单表: -
orderid custid date
-------- ------ -----
101 1 2016-03-01
102 1 2016-03-03
103 2 2016-03-01
现在,我们有谁已经下任何订单
显示客户我们能够做到几个方面: -
1.Without加入
Select custid
from Customers
where custid not in
(Select custid from Orders)
和
2.具有加入
Select C.custid
from Customers C left join Orders O
on C.custid = O.custid
where O.orderid is null
我被问到是否会有任何性能差异?如果哪个更好,为什么?
'2.删除第二个查询中的where子句给出错误结果 –
它们在OP变体中给出了相同的结果。 2排。没有WHERE子句,它给832行 –