【转载】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方式,太神奇了。分享段示例代码:
1
update
tb_User
2
set
pass=
''
3
from
tb_User usr
4
inner
join
tb_Address addr
on
usr.nAddressFK = addr.nAddressID
5
where
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
注意蓝色部分。