代码改变世界

【转载】SQL中使用update inner join和delete inner join

2010-03-24 10:26  Virus-BeautyCode  阅读(983)  评论(0编辑  收藏  举报

原文地址:SQL中使用update inner join和delete inner join

 

 

Update XXX set XXX where 这种写法大家肯定都知道,才发现update和delete居然支持inner join的update方式,太神奇了。分享段示例代码:

1update tb_User
2set pass=''
3from tb_User usr
4inner join tb_Address addr on usr.nAddressFK = addr.nAddressID
5where usr.id=123

update的格式是

update t1 set t1.name=’Liu’ from t1 inner join t2 on t1.id = t2.tid

delete 语句也是类似

delete from t1 from t1 inner join t2 on t1.id = t2.tid

注意蓝色部分。