updatesql兩個表
㈠ sql update 的更新值來源於另外一個表,如何實現
1、創建兩個測試表,
createtabletest_up_a(idnumber,valuevarchar2(100));
createtabletest_up_b(idnumber,valuevarchar2(100));
2、分別往兩個表中插入數據;
insertintotest_up_avalues(1,'A1');
insertintotest_up_avalues(2,'A2');
insertintotest_up_avalues(3,'A3');
insertintotest_up_avalues(4,'A4');
insertintotest_up_avalues(5,'A5');
insertintotest_up_avalues(6,'A6');
insertintotest_up_bvalues(1,'BBBB1');
insertintotest_up_bvalues(2,'BBBB2');
insertintotest_up_bvalues(5,'BBBB5');
commit;
3、分別查看兩個表中數據;
select'TBL_A',t.*fromTEST_UP_At
unionall
select'TBL_B',t.*fromTEST_UP_Bt
4、執行更新腳本,可以發現TEST_UP_A.VALUE值已變化;
updateTEST_UP_At
sett.value=
(selectb.value
fromTEST_UP_Bb
wheret.id=b.id
andrownum=1)
㈡ sql update 兩個表更新問題
update tbjmjkda a
set a.jgbm=b.SJJGBM
from tbyljg b where a.JGBM=B.JGBM
AND
b.jglx like '%下屬科室%'