table1ip parentip
6  | 2
3  | 2
5  | 3
2  | 1
table2ip newip
2 | 12
3 | 13
4 | 14
如何根据table2更新table1的ip和parentip就是说把table1中所有的ip换成table2中的newip。

解决方案 »

  1.   

    update table1 A,table2 B
    set A.ip = B.newip
    where A,parentip = B.ip
      

  2.   

    update table1 inner join table2 on table1.ip=table2.ip
    set table1.parentip = table2.parentip
      

  3.   

    update table1 A,table2 B set A.ip = B.newip where A.parentip = B.ip
    or
    update table1 A inner join table2 B on A.parentip = B.ip set A.ip = B.newip 
      

  4.   

    没有任何冒犯的意思,回贴中的SQL语句执行的话都会报错。
    SQL版本是 5.0.67
      

  5.   

    WWWWAupdate oldip A,nip B 
    set A.ip = B.newip 
    where A.parentip = B.ip这样写的话,会报错,duplicate entry '12' for key1
      

  6.   

    sql虽然写的不对。但是精神已经领会。。
    修改了一下就可以了
    谢谢楼上各位~