简体   繁体   中英

update table from another table in db2 9

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???

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM