sqlupdatedelete中使⽤innerjoin
Update
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
MYSQL,ACCESS 写法如下:
sql中delete用法
UPDATE mem_world AS mw1 INNER JOIN mem_world  AS  mw2
ON  mw1.parentid = mw2.wid
SET mw1.level= mw2.level
WHERE mw2.baseid =107
AND  mw2.parentid =0
AND  mw2.size >1;
on是表连接的筛选条件
就是说,表连接后,会产⽣⼀个类似于临时的视图这么⼀个东西
where是从这个临时的视图中筛选数据的
所以,你⾸先要搞清,你的所谓的2个条件属于哪⼀种
Delete
delete 语句也是类似
delete from t1 from t1 inner join t2 on t1.id = t2.tid
注意蓝⾊部分。
mysql:
DELETE mwb FROM  mem_world_building AS mwb INNER JOIN mem_world AS mw
ON mwb.wid = mw.wid
pe between11and15
and baseid =107
and mw.parentid <>0
and  mw.size >1;
下⾯是ORACLE的:
DELETE TABLE1 where exists ( select1from table2 where and table1.khid=table2.khid and FWDWID=8);
DELETE TABLE1 where KHID exists ( select KHID from table2 where FWDWID=8)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。