2014-07-13 16:29:16
来 源
中存储网
MySQL
CREATE TABLE `tb1` ( `id` int(11) NOT NULL, `A` varchar(100) default NULL, `B` varchar(100) default NULL, `C` varchar(20) default
CREATE TABLE `tb1` (
  `id` int(11) NOT NULL,
  `A` varchar(100) default NULL,
  `B` varchar(100) default NULL,
  `C` varchar(20) default NULL,
  PRIMARY KEY  (`id`),
  KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `tb2` (
  `id` int(11) NOT NULL,
  `A` varchar(100) default NULL,
  `B` varchar(100) default NULL,
  PRIMARY KEY  (`id`),
  KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

级联更新1: update tb1,
tb2
set tb1.a=tb2.a,tb1.b=tb2.b
where tb1.id=tb2.id

级联更新2:
update tb1,
(select * from tb2) as tb2
set tb1.a=tb2.a,tb1.b=tb2.b
where tb1.id=tb2.id

级联更新3:
update (select * from tb1 group by C) as temp,
       tb2,
       tb1
set tb1.a = tb2.a,
    tb1.b = tb2.b
where tb1.id = tb2.id and
      temp.id = tb2.id

级联更新4:
update tb1 left join tb2 on tb1.id = tb2.id
set tb1.a = tb2.a,
    tb1.b = tb2.b
where ......

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。