update 表一对多 的语句
表A:
id name content
1 a a
2 b b
3 c c
表B:
id name body
1 b bbbb
2 c cccc
3 a aaaa
4 a aaaa
5 b bbbb
6 c cccc
现在希望通过name字段将两表联接起来,更新表A ,
结果:
表A
id name content
1 a aaaaa
2 b bbbbb
3 c ccccc
表A和表B是一对多的关系,请问怎样写SQL呢,?谢谢了
[解决办法]
update a
set content = a.content + c.cody
from a,
(select name , max(body) body from b group by name) c
where a.name = c.name