SQL优化在左联接
原始代码:
select A.* ,isnull(c.name,'')
into #temp
from A join B on A.id =B.id
left join c on a.id=c.id
优化代码:
Select a.* ,
'' as name -- creating a dummy column which can be updated later
into #temp
from A join B on A.id =B.id
update #temp
set name =c.name
from #temp a
join c on a.id=c.id
正确吗?
Original Code:
select A.* ,isnull(c.name,'')
into #temp
from A join B on A.id =B.id
left join c on a.id=c.id
Optimized Code:
Select a.* ,
'' as name -- creating a dummy column which can be updated later
into #temp
from A join B on A.id =B.id
update #temp
set name =c.name
from #temp a
join c on a.id=c.id
Is it correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果每个
a.id
最多匹配一个c.id
,那么是的,否则第一个插入将插入比第二个插入更多的行。If every
a.Id
matches at most onec.Id
, then yes, otherwise the first INSERT will insert more rows than the second.