Update table with value from another table

不想你离开。 提交于 2019-12-13 05:25:43

问题


I try to update value from one table with another table by use IP_ID to compare 2 table by following sybtax

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

The error I found was DB2 Database Error:

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

even I change = to in it's told me another error DB2 Database Error:

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

I am coding in DB2.


回答1:


your misunderstanding

'UPDATE t1 SET value=onevalue'

onevalue needs to be a single value. You may achieve this by (SELECT value FROM t2 WHERE t1.id = t2.id FETCH FIRST 1 ROW ONLY)



来源:https://stackoverflow.com/questions/14312885/update-table-with-value-from-another-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!