我正在尝试使用JOIN
删除记录,但是无法正常工作,因此我尝试使用IN
来删除记录也无法正常工作。但是,如果我将DELETE
更改为SELECT
,则可以正常工作。
SELECT * FROM T1
WHERE T1.ID IN (
SELECT T1.ID FROM T1
JOIN T2 ON T2.PID = T1.ID WHERE T2.Email LIKE '%mitul%')
DELETE FROM T1
WHERE T1.ID IN (
SELECT T1.ID FROM T1
JOIN T2 ON T2.PID = T1.ID WHERE T2.Email LIKE '%mitul%')
DELETE FROM T1
JOIN T2 ON T2.PID = T1.ID WHERE T2.Email LIKE '%mitul%'
答案 0 :(得分:4)
您可以在DELETE
语句后提及表名或表别名:
DELETE T1
FROM T1
JOIN T2 ON T2.PID = T1.ID
WHERE T2.Email LIKE '%mitul%'
请在db<>fiddle上找到演示
如果要从两个表中删除匹配的条目,请在T1, T2
语句后使用DELETE
。
DELETE T1, T2
FROM T1
JOIN T2 ON T2.PID = T1.ID
WHERE T2.Email LIKE '%mitul%'