A quick test with DB2 (9.7 LUW) reveals that this works within one level of subquery, but not more than one. This works:
update foo f
set bar = (
select count(*) from baz where f.bar = baz.bar
)
This does not work:
update foo f
set bar = (
select count(*) from (
select * from baz where f.bar = baz.bar
)
)
Why is this? Who knows. It is just one of many mysteries of DB2 syntax.
In any case, this is a bad style of coding (just like the person who gave you the example implied). You should use MERGE
when you want to do an update based on the contents of other tables:
merge into foo f
using baz b
on foo.bar = baz.bar
when matched then update set
foo.bar = 123;