三张关联的表,如何通过DELETE语句同时删除三张表的同一ID内容?

2024-11-09 10:08:57
推荐回答(1个)
回答1:

例如三个表A,B,C的关联:
如果B的二级数据或C的二级数据不一定存在,用以下语句:
delete A,B,C from A left join B on B.id_b=A.id left join C on C.id_c=A.id where (B.id_b=A.id) or (C.id_c=A.id);
删除3个表都存在的关联数据:
delete A,B,C from A,B,C where A.id=B.id_b and A.id=C.id_c。