SQL 两个表关联更新(Update)写法
2011/7/22 17:27:58 类别:数据库摘要:整理多表数据关联时用到此SQL 语法老是报错,查询一下,备注一下以备不时之需
这里就直接贴代码了
--更新关联字段 这里用的LIKE关联 相信如果是=或者别的条件,你一定可以写出来噢! Update PostCode Set PID=Area_Base.ID From Area_Base,PostCode Where PostCode.XianName like Area_Base.Area_ShortName+'%' ANd Area_Base.Area_Level=3
再写一个多字段更新的,就直接从网上贴来,不解释了
update customers a set (city_name,customer_type)=(select b.city_name,b.customer_type from tmp_cust_city b where b.customer_id=a.customer_id) where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id )
如果还有不明白的就Q我吧,或者在评论中留言~