I have the problem of needing to update multiple columns (2) in multiple rows (7) from a subselect query.
Here is what I have so far:
UPDATE commandtbl2 t1
SET (attr, attr2) = (
SELECT attr, attr2
FROM commandtbl3 t2
WHERE t1.cmd=t2.cmd
);
However when I let that run I get SQLCODE=-811, SQLSTATE=21000
(THE RESULT OF AN EMBEDDED SELECT STATEMENT OR A SUBSELECT IN THE SET CLAUSE OF AN UPDATE STATEMENT IS A TABLE OF MORE THAN ONE ROW, OR THE RESULT OF A SUBQUERY OF A BASIC PREDICATE IS MORE THAN ONE VALUE)
Where is my mistake? It should change the 2 columns in 3 rows and leave the others rows as they are. I can only use SQL so no Java, PHP and so on.
Since this is DB2 solutions I have found online like:
UPDATE commandtbl2 t1
SET attr = t2.attr, attr2=t2.attr2
FROM commandtbl2 t1
JOIN commandtbl3 t2
ON t1.cmd = t2.cmd ;
Or
UPDATE
commandtbl2 t1
JOIN
commandtbl3 t2 ON t1.cmd=t2.cmd
SET
t1.attr = t2.attr,
t1.attr2=t2.attr2;
don't work but throw exceptions.
Thanks for your help.
TheVagabond