如果“t1”和“t1.status = E”中存在“t2.t1_id”,我需要从“t2”中删除行
表格结构,
t1(结构)
id status
1 E
2 A
3 A
4 E
5 C
t2(结构)
id t1_id
1 1
2 2
3 3
4 4
5 5
注意:t1_id forign键参见table_1.id
感谢,
答案 0 :(得分:2)
答案:
DELETE FROM t2 WHERE t1_id IN (
SELECT id FROM t1 WHERE status='E'
)
查询后的预期结果为:
id t1_id
2 2
3 3
5 5
答案 1 :(得分:1)
试试这个: -
DELETE t2,t1
FROM t1
INNER JOIN t2 ON t1.id = t2.t1_id
WHERE t1.status = 'E';