我正在尝试正确匹配左联接,在其中删除filter
和X表中为此过滤器记录的信息。
表d_category
filter_id
7
8
表d_name
id | filter_id
10 | 7
11 | 7
12 | 7
表product_d
product_id | d_name_id
50 | 10
50 | 11
50 | 12
查询
$this->db->query("DELETE FROM product_d
LEFT JOIN d_name ON (product_d.d_name_id = d_name.id)
WHERE"); // what should this clause be?
答案 0 :(得分:3)
我假设您正在寻找级联删除。如果是这样的话:
如果您将外键配置为具有cascade delete
,则从父表中删除记录时,所有相关数据也将被删除。
CREATE TABLE rooms (
room_no INT PRIMARY KEY AUTO_INCREMENT,
room_name VARCHAR(255) NOT NULL,
building_no INT NOT NULL,
FOREIGN KEY (building_no)
REFERENCES buildings (building_no)
ON DELETE CASCADE
);
然后,当您删除建筑物时,房间也会被删除
DELETE FROM buildings
WHERE
building_no = 2;