问题
hi i run this script " UPDATE t1 SET T1.col1= T2.col1 FROM aaa t1 , bbb t2 WHERE T1.col2=138802 AND T1.col3 >=8800084 and T1.col3 <=8852884 AND T1.col4=0 AND T1.col5=T2.col2" and i get syntax error !!! (ILLEGAL USE OF KEYWORD FROM) how i can run this script???
回答1:
Here's a modified version:
UPDATE aaa t1
SET T1.col1 = (SELECT T2.col1 FROM bbb t2 WHERE T1.col5=T2.col2)
WHERE T1.col2=138802 AND T1.col3 >=8800084 and T1.col3 <=8852884 AND T1.col4=0
I isolated the T2 stuff in a subquery with an explicit SELECT. Note that the subquery will run for every row that is updated.
来源:https://stackoverflow.com/questions/4708082/update-table-from-another-table-in-db2-9