我想从两个表中删除行 [英] I want to delete row from both table
问题描述
如果我触发要删除的查询,它只会从一个表中删除,而不是同时删除两个表.请帮我找到解决方案.下面给出了我尝试过的查询.
If i fire query to delete, it deletes only from one table not to both . please help me find solution . given below the query i have tried.
DELETE m.* FROM master m
INNER JOIN field f ON m.id = f.label_id
WHERE f.id='13'
Mater 表正在删除,但不是在字段表的情况下.
Mater table is deleting but not in case of field table.
推荐答案
为了从
m
和f
两个表中删除条目加入结果:
In order to delete entries from both tables
m
andf
out of joined results:
DELETE m,f FROM master m
INNER JOIN field f ON m.id = f.label_id
WHERE f.id='13';
为了从表 m
中删除连接结果中的条目:
In order to delete entries from table m
out of joined results:
DELETE m FROM master m
INNER JOIN field f ON m.id = f.label_id
WHERE f.id='13';
为了从表f
中删除连接结果中的条目:
In order to delete entries from table f
out of joined results:
DELETE f FROM master m
INNER JOIN field f ON m.id = f.label_id
WHERE f.id='13';
注意:一个更好的方法可能是放置一个具有ON DELETE CASCADE
行为的外键约束.但为此,您需要 InnoDb 作为您的存储引擎.
Note: A better method might be to put a foreign key constraint having the behavior ON DELETE CASCADE
. But for that you need InnoDb as your storage engine.
这篇关于我想从两个表中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!