【发布时间】:2010-12-22 04:58:14
【问题描述】:
我在 UPDATE 中使用子查询:
UPDATE tableA
SET x,y,z = ( (SELECT x, y, z
FROM tableB b
WHERE tableA.id = b.id
AND (tableA.x != b.x
OR tableA.y != b.y
OR tableA.z != b.z))) );
我的问题是,如果子查询没有返回行会发生什么?它会使用 null 进行更新吗?
其次,有没有更好的方法来写这个。我基本上是从 tableB 更新 tableA 中的三个字段,但只有在三个字段中的任何一个不同时才会更新。
【问题讨论】:
-
这个更新应该基于 tableB 的连接参数还是“笛卡尔更新”?
-
the update should only happen if any of the three fields are different.对我来说听起来像是 where 子句...
标签: sql database subquery sql-update informix