问题
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