我想做这样的事情:
update t1 set t1.column1 = 'changed'
from left outer join t2 on t1.dataid = t2.dataid
where t2.column2 != 'foo';
基本上,在t2
确定t1
要更新的记录时,我需要检查某些内容。我该如何使它在语法上正确?
当不必将关联表中的值转移到更新后的表中时,与其建立LEFT JOIN相比,在WHERE子句中建立与另一个表的关联更为简单。
它看起来像这样:
update t1 set t1.column1 = 'changed'
where not exists (select 1 from t2 where t1.dataid = t2.dataid and t2.column2='foo');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句