[英]MySQL, php table question (delete on an update)
I have the two following tables我有以下两个表格
table A
| id | name |
| 1 | bob |
| 2 | jill |
| 3 | jojo |
Table A is displayed by using checkboxes.表 A 使用复选框显示。
On the first go, the user checks all three checkboxes so you get the result in table B.在第一个 go 上,用户选中所有三个复选框,以便您在表 B 中获得结果。
table B
| table_a_id | table_c_id |
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
But the next time the user goes to edit, they UNCHECK '2' so that it's only:但是下次用户进行编辑时,他们取消选中“2”,因此它只是:
1
3
How do I write my query (using either mySQL or php) so that TABLE B is updated to:如何编写查询(使用 mySQL 或 php)以便将表 B 更新为:
| table_a_id | table_c_id |
| 1 | 2 |
| 3 | 2 |
DELETE A,B
FROM A
LEFT JOIN B
ON B.table_a_id = A.id
WHERE A.id NOT IN (1,3)
Or use InnoDB with aForeign key ON DELETE CASCADE
, much simpler:)或者使用带有外键的 InnoDB
ON DELETE CASCADE
,更简单:)
DELETE
FROM TableB
WHERE (NOT table_a_id IN (1, 3))
AND (table_c_id = 2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.