复制字段到另一个表!

leechunchao 2011-01-17 04:31:07
A表(tid pk,tcontent),B表(tid pk,tcontent),将B表中的tcontent复制到A表中的tcontent中,A表的tid与B表的tid一样。语句应该如何实现呢?
...全文
138 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bennydeng 2011-02-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 acmain_chm 的回复:]

update b inner join a on b.tid=a.tid
set b.tcontent=a.tcontent
[/Quote]


非常感谢
leechunchao 2011-01-17
  • 打赏
  • 举报
回复
我写了一个,update a set a.tcontent = ( select b.tcontent from b where a.tid = b.tid ),感觉不是很好。呵呵,谢谢大家了。
小小小小周 2011-01-17
  • 打赏
  • 举报
回复
update A,B 
set A.tcontent=b.tcontent
where A.tid=B.tid
WWWWA 2011-01-17
  • 打赏
  • 举报
回复
update a inner join b on b.tid=a.tid set a.tcontent=b.tcontent
or
update a,b set a.tcontent=b.tcontent where b.tid=a.tid
ACMAIN_CHM 2011-01-17
  • 打赏
  • 举报
回复
如果考虑B中有而A中没有的,并且 TID字段是唯一键的话可以。
insert into A
select * from b
ON DUPLICATE KEY UPDATE
tcontent=values(tcontent)
ACMAIN_CHM 2011-01-17
  • 打赏
  • 举报
回复
方向反了。(将B表中的tcontent复制到A表中的tcontent中)

update a inner join b on b.tid=a.tid
set a.tcontent=b.tcontent
ACMAIN_CHM 2011-01-17
  • 打赏
  • 举报
回复
update b inner join a on b.tid=a.tid
set b.tcontent=a.tcontent

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧