Update XXX set XXX where 这种写法大家肯定都知道,才发现update和delete居然支持inner join的update方式,太神奇了。分享段示例代码:
update tb_User set pass='' from tb_User usr inner join tb_Address addr on usr.nAddressFK = addr.nAddressID 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
注意蓝色部分。