我有两张桌子:
USER
MAILING
MAILING
表有一列email
。
USER
表有users
很多email
。
现在我想删除这样的东西:
DELETE email FROM mailing WHERE users.email = mailings.email
因此,如果此电子邮件存在于用户表中,我需要从表邮件中删除电子邮件。
我有两张桌子:
USER
MAILING
MAILING
表有一列email
。
USER
表有users
很多email
。
现在我想删除这样的东西:
DELETE email FROM mailing WHERE users.email = mailings.email
因此,如果此电子邮件存在于用户表中,我需要从表邮件中删除电子邮件。
你可以用这个
DELETE FROM mailing WHERE email IN (SELECT email FROM users)
或者这个使用JOIN
DELETE M
FROM mailing M
JOIN users U
ON M.email = U.email
如果要更新列,请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
您可以使用EXISTS
MySQL 的子句如下 -
delete from mailing where exists(select * from user where user.email=mailing.email);
考虑到您想从邮件表中删除所有行,而邮件表中只有一列。
Delete
from mailing where mailing.email
exists (select email from users where users.email = mailing.email);