我想使用INNER JOIN在DB2表上创建UPDATE语句 我试试这个
update TABLE1 set FIELDVALUE='text/html' from TABLE1 as T1
inner join TABLE2 as T2 on T1.PROFILE_ID = T2.PROFILE_ID
inner join TABLE3 as T3 on T2.MSGTYPE_ID = T3.MSGTYPE_ID
where T1.NAME='contentType' and T3.NAME='Order';
我提到选择正常
select * from TABLE1 as T1 inner join TABLE2 as T2
on T1.PROFILE_ID = T2.PROFILE_ID
inner join TABLE3 as T3 on T2.MSGTYPE_ID = T3.MSGTYPE_ID
where T1.NAME='contentType' and T3.NAME='Order';
谢谢!
答案 0 :(得分:1)
Db2不允许“update + join”语法。但是,你可以像这样重写你的sql(未经测试):
update TABLE1 set FIELDVALUE='text/html'
where table1.primary_key in (
(
select t1.primary_key
TABLE1 as T1
inner join TABLE2 as T2 on T1.PROFILE_ID = T2.PROFILE_ID
inner join TABLE3 as T3 on T2.MSGTYPE_ID = T3.MSGTYPE_ID
where T1.NAME='contentType' and T3.NAME='Order'
);