我想知道是否有任何解决方案可以在一个查询中删除多行?
我使用具有多个输入的选择元素,因此当我发送表单时,我的 $_POST 中有一个数组。
例如,我想从一张表中取消订阅用户的多节类(class),所以我有:
users.id | lesson.id
--------------------
1 | 1
1 | 2
1 | 3
1 | 4
我的选择向我发送了一个包含 Lesson.id 的数组:
Array
(
[0] => 2
[1] => 3
[2] => 4
)
如何仅通过一个查询删除表中的所有行?
顺便说一句,我一直都知道 users.id。
最佳答案
如果您只想删除这三个lesson_id
delete from lesson_table
where users_id = 1 and lesson_id in (2, 3, 4)
如果您想删除除一门任意类(class)之外的所有类(class),并且您知道用户 1 有 4 节类(class),那么您可以限制
删除 3 个 Lesson_ids
delete from lesson_table
where users_id = 1
limit 3
关于mysql - MySQL中删除具有特定参数的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13811097/