首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

条件update,多谢啦

2012-10-18 
条件update,谢谢啦table1:idstatustable2Idtable2:idstatus1111021220311402table2Id为外键要求当table1的

条件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

热点排行