A表(tid pk,tcontent),B表(tid pk,tcontent),将B表中的tcontent复制到A表中的tcontent中,A表的tid与B表的tid一样。语句应该如何实现呢?

解决方案 »

  1.   

    update b inner join a on b.tid=a.tid
    set b.tcontent=a.tcontent
      

  2.   

    方向反了。(将B表中的tcontent复制到A表中的tcontent中) update a inner join b on b.tid=a.tid
    set a.tcontent=b.tcontent
      

  3.   

    如果考虑B中有而A中没有的,并且 TID字段是唯一键的话可以。
    insert into A
    select * from b
    ON DUPLICATE KEY UPDATE
    tcontent=values(tcontent)
      

  4.   

    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
      

  5.   

    update A,B 
    set A.tcontent=b.tcontent
    where A.tid=B.tid
      

  6.   

    我写了一个,update a set a.tcontent = ( select  b.tcontent from b   where a.tid = b.tid ),感觉不是很好。呵呵,谢谢大家了。