一、关联查询修改表数据:

UPDATE tms_test_rms,spms_project_view  SET tms_test_rms.isRead = 1  where tms_test_rms.code = spms_project_view.code and spms_project_view.status=6

 

二、多表删除和更新:

  1.从表t1里删除这样一些行,其ID值可以在另一个表里t2里找到的所有行全部删掉

  delete t1,t2 from t1 inner join t2 on t1.id=t2.id

  注意:如果列名出现在多个表里,必须用表的名字对它加以限定。

  2.delete还支持一种写法,可以一次删除多个表里的行,那么必须在delete关键字的后面写出这俩个表的名字

  delete t1,t2 from t1 inner join t2 on t1.id=t2.id

  3.想要从表t1 里把在表t2 中没有匹配的行找出来

  select t1.* from t1 left join t2 on t1.id=t2.id where t2.id is null

   同样从表t1找出并删除那些行:

  delete t1 from t1 left join t2 on t1.id=t2.id where t2.id is null

  4.Mysql还支持另一种多表delete语法,列出那些需要删除行的表,并使用using 子句来链接这些表,从而确定那些行是需要删除的:

  (1)delete from t1 using t1 inner join t2 on t1.id=t2.id;

    (2) delete from t1,t2 using t1 inner join t2 on t1.id=t2.id

  5.update多表操作:

  (1)update score,grade_event set score.score=score.score + 1 where score.event_id=grade_event.event_id and grade_event.date='2012-09-23' AND                        grade_event.category='Q' 

    (2) 同样实现:

    update score set score=score+1 where event_id in (select event_id from grade_event where date='2012-09-23' and category='Q')

   (3) update t1,t2 set t2.a= t1.a where t2.id=t1.id

魏巍周山,似曾乡山,凭窗远望,似曾南北。