我正在嘗試用表 A 中的值更新表 B 中的一列,其中 passport_no 匹配。
下面是我的sql查詢。
update tabel_b
set b.country_id = a.national_id
from table_a a
join tabel_b b on b.passport_no = a.passport_no
where a.is_deleted = false;
在執行時,我得到錯誤:關系“tabel_b”的列“b”不存在
請問我該怎么做。
uj5u.com熱心網友回復:
直接的錯誤是您無法限定要更新的列。所以應該是set country_id = ...
然而,更大的問題是你的加入。
如手冊中所述
不要將目標表作為 from_item 重復,除非您打算進行自聯接
所以正確的說法很可能應該是:
update tabel_b
set country_id = a.national_id
from table_a a
where b.passport_no = a.passport_no
and a.is_deleted = false;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/418793.html
標籤:
