update table from another table in db2 9

╄→гoц情女王★ 提交于 2019-12-11 16:38:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!