我想从两个表中删除行 [英] I want to delete row from both table

查看:31
本文介绍了我想从两个表中删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我触发要删除的查询,它只会从一个表中删除,而不是同时删除两个表.请帮我找到解决方案.下面给出了我尝试过的查询.

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.

推荐答案

  1. 为了从 mf 两个表中删除条目加入结果:

  1. In order to delete entries from both tables m and f 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆