table a
字段:
Id,Code,des
唯一键 Id,Code
数据:
1 , 'CN' , '水'
2 , 'CN' , '火'
table b
字段:
Id,Code,des
唯一键 Id,Code
数据:
1 , 'CN' , 'shui'
2 , 'CN' , 'huo'问题:怎样通过update,从a表更新b表的数据.
得到这样的结果:
1 , 'CN' , '水'
2 , 'CN' , '火'
我写的如下:
update b set b.des=
(select a.des
from a
where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
这样写的b表结果是:
1 , 'CN' , '水'
2 , 'CN' , '水'
如果我写
update b set (b.id,b.des)=
(select a.id,a.des
from a
where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
则提示关于违反唯一约束性.
字段:
Id,Code,des
唯一键 Id,Code
数据:
1 , 'CN' , '水'
2 , 'CN' , '火'
table b
字段:
Id,Code,des
唯一键 Id,Code
数据:
1 , 'CN' , 'shui'
2 , 'CN' , 'huo'问题:怎样通过update,从a表更新b表的数据.
得到这样的结果:
1 , 'CN' , '水'
2 , 'CN' , '火'
我写的如下:
update b set b.des=
(select a.des
from a
where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
这样写的b表结果是:
1 , 'CN' , '水'
2 , 'CN' , '水'
如果我写
update b set (b.id,b.des)=
(select a.id,a.des
from a
where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
则提示关于违反唯一约束性.
(select a.des
from a
where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
where exists (select * from a where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
and a.Code = b.Code
and a.Code = 'CN')
这个我已经加的了,多谢你的提供.
只是我想要的结果依然不对
update b set b.des=
(select a.des
from a
where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
where exists (select 1 from a where a.id=b.id
and a.Code = b.Code
and a.Code = 'CN')
也是正确的