当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - 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 table is deleting but not in case of field table.

网友答案:
  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';
    
  2. 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';
    
  3. 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';
    

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: