I'm trying to properly match a left-join, where you delete filter
and information pieces that are recorded in X table for this filter.
table d_category
filter_id
7
8
table d_name
id | filter_id
10 | 7
11 | 7
12 | 7
table product_d
product_id | d_name_id
50 | 10
50 | 11
50 | 12
The Query
$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?
I assume that you are looking for Cascading Delete . If that is the case:
If you configure your Foreign Keys to have cascade delete
, all related data will also get deleted when you delete record from parent table.
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
);
then when you delete building, rooms also get deleted
DELETE FROM buildings
WHERE
building_no = 2;
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.