日期:2014-05-16  浏览次数:20876 次

条件update,谢谢啦
table1: id status table2Id table2: id status
  1 1 1 1 0
  2 1 2 2 0
  3 1 1
  4 0 2
table2Id为外键 要求当table1的 table2Id = n的 所有status均为1时,将table2的 id = table2Id行的status 更新为1

------解决方案--------------------
update table2
set status=1
where 1=(select min(status) from table1 where table2Id=table2.id)
------解决方案--------------------
UPDATE table1 a,table2 b
SET b.status=1
WHERE a.table2id=b.id and a.status=1