简体   繁体   中英

how to delete multiple records with one query

i would like to delete multiple records with one query using mysql and php instead of using any loops.

$query = "DELETE FROM countries c WHERE c.id = 8";

what is the syntax for that?

$query = "DELETE FROM countries c WHERE c.id in(4,5,6,7,8,89,9, ....)";


$query = "DELETE FROM countries c WHERE c.id > 5  and c.id < 25";

I think you should use

$query = "DELETE FROM countries c WHERE c.id = 8 OR c.id = 9 OR c.id = 10";

Didn't test this code but I think it should work.

如果您知道所有ID,则可以说“在(8,9,10)中的c.id中”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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