执行UPDATE语句时出现‘Column 'PropertyAddress' in field list is ambiguous’报错
解决UPDATE语句中"Column 'PropertyAddress' ambiguous"报错问题
报错原因
你执行的UPDATE语句里,set PropertyAddress未指定对应的表别名(a或b),由于通过JOIN关联了两个同结构的mytable实例(别名a和b),两个表都包含PropertyAddress字段,MySQL无法确定要更新的是哪个表的该字段,因此抛出“字段列表中的列'PropertyAddress'不明确”的错误。另外语句里set PropertyAddress = updat中的updat是笔误,需替换为用于填充的目标值。
修正后的UPDATE语句
update mytable a join mytable b on a.ParcelID = b.ParcelID and a.UniqueID <> b.UniqueID set a.PropertyAddress = b.PropertyAddress where a.PropertyAddress is null;
说明
- 在
set子句中明确指定要更新表a的PropertyAddress字段(a.PropertyAddress),消除字段歧义 - 将错误的
updat替换为b.PropertyAddress,结合WHERE条件(a表该字段为空),直接用同ParcelID下b表的非空地址填充即可
内容的提问来源于stack exchange,提问作者Abrar M
相关产品推荐
相关产品推荐

