有两个表,表一  archives  中有字段  id   title  type  
          表二  arctype  中有字段  id    type表一archives有数据
id   title   type 1    有人    55
 2    一些    56
 3    人类    55
 4    鸟类    55
表二arctype有数据
id    type 1      55
 2      56
 3      55
 4      55我现在需要将title中含有 人 这个字的,type又为55的  内容  的 type  变为   44那我执行 UPDATE archives SET type=44 WHERE title LIKE '%人%' AND type = 55但这样只能改变一个表,执行结果如下表一archives有数据
id   title   type 1    有人    44
 2    一些    56
 3    人类    44
 4    鸟类    55
表二arctype有数据
id    type 1      55   这里没有变
 2      56
 3      55    这里没有变   我需要这里也改变
 4      55我需要两个表的中数据能同步改变。这条sql语句,怎么写?

解决方案 »

  1.   

    只能分2条语句执行,或在表下建触发器:update arctype a inner join archives b on a.id=b.id
    set a.type=44
    where b.title LIKE '%人%' AND b.type = 55;UPDATE archives SET type=44 WHERE title LIKE '%人%' AND type = 55;
      

  2.   

    update archives a,arctype b set a.type='44',b.type='44' where a.id=b.id and a.title like '%人%' and a.type='55';