简体   繁体   English

MySQL更新更新所有行?

[英]MySQL update updating all rows?

I'm trying to create an sql query that will check through a table and if it cannot find a row in a different table with the same id then it modifies a field in the original table. 我正在尝试创建一个将查询表的sql查询,如果它无法在其他表中找到具有相同id的行,那么它将修改原始表中的字段。

UPDATE book SET reserved = 'N' WHERE not exists ( SELECT * FROM reservedbooks WHERE book = $row[bookID]

I'm running this in a loop in php where $row[bookID] represents all the book ids. 我正在php中的循环中运行此代码,其中$ row [bookID]表示所有书ID。 my problem is that when this finds a match it sets all of 'reserved' columns values to 'N', not just the one it cant find a value for. 我的问题是,当找到匹配项时,会将所有“保留”列的值都设置为“ N”,而不仅仅是为其找不到值的列。

any help would be greatly appreciated :) 任何帮助将不胜感激 :)

用这个:

UPDATE book SET reserved = 'N' WHERE id not in ( SELECT id FROM reservedbooks WHERE book = $row[bookID]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM