更新表与另一个表中的值(Update table with value from another t

2019-10-30 23:34发布

我试图从一个表,使用IP_ID另一个表更新值由下列sybtax比较2表

UPDATE EDWID02.CUSTOMER_MOBILE t1
   SET T1.MOBILE = (
      SELECT T2.MOBILE
      FROM EDWID02.NEW_MOBILE t2
      WHERE T1.IP_ID=T2.IP_ID)

我发现错误是DB2数据库错误:

ERROR [21000] [IBM][DB2/AIX64] SQL0811N  The result of a scalar fullselect, 
SELECT INTO statement, or VALUES INTO statement is more than one row.  
SQLSTATE=21000

即使我改变=在它告诉我另一个错误DB2数据库错误:

ERROR [42601] [IBM][DB2/AIX64] SQL0104N  An unexpected token "in" was found
following "t1    SET T1.MOBILE".  Expected tokens may include:  "=".
SQLSTATE=42601

我编码DB2。

Answer 1:

你误会

'UPDATE t1 SET value=onevalue'

onevalue需要是一个单一的值。 您可以做到这一点(FROM T2 SELECT值,其中t1.id = t2.id FETCH FIRST 1个ROW ONLY)



文章来源: Update table with value from another table
标签: db2