0

我有两张桌子:

  • USER
  • MAILING

MAILING表有一列email

USER表有users很多email

现在我想删除这样的东西:

DELETE email FROM mailing WHERE users.email = mailings.email 

因此,如果此电子邮件存在于用户表中,我需要从表邮件中删除电子邮件。

4

4 回答 4

2

你可以用这个

DELETE FROM mailing WHERE email IN (SELECT email FROM users)

或者这个使用JOIN

DELETE M
FROM mailing M
  JOIN users U
    ON M.email = U.email 
于 2013-10-17T13:01:15.960 回答
0

如果要更新列,请update不要尝试delete

UPDATE mailing 
inner join users on users.email = mailings.email  
set email=null 

或者你想删除记录试试这个:

DELETE m 
FROM mailing m 
inner join users u on u.email=m.email
于 2013-10-17T13:01:04.503 回答
0

您可以使用EXISTSMySQL 的子句如下 -

delete from mailing where exists(select * from user where user.email=mailing.email);

无需使用 JOIN

于 2013-10-17T13:47:48.163 回答
0

考虑到您想从邮件表中删除所有行,而邮件表中只有一列。

Delete
from mailing where mailing.email 
exists (select email from users where users.email = mailing.email);
于 2013-10-17T13:02:21.170 回答