mysql 与内连接相反

发布于 2024-10-10 06:52:05 字数 268 浏览 0 评论 0原文

我想使用我的数据库通过电子邮件联系我的用户。我想确保我不会意外地两次联系同一用户。为此,我有一个表格来跟踪谁被联系以及何时被联系。

当我执行 MYSQL 查询时,我想从 email 表中选择电子邮件,并确保 contacted 表中不存在这些条目。

用一句话来表达:如果电子邮件不在 Contacted_Table 中,则从 Email_Table 中选择电子邮件

也许有一种完全不同的方法。我愿意接受所有建议:)谢谢:)

I want to contact my users via email using my database. I want to make sure that I don't accidentally contact the same user twice. For that, I have a table that tracks who got contacted and when.

When I do my MYSQL query I want to select emails from the the email table and make sure none of those entries exists in the contacted table.

To phrase it in a sentence: select email from Email_Table if they are not in Contacted_Table

Perhaps there is a completely different approach. I am open to all suggestions :)Thank you :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

撞了怀 2024-10-17 06:52:05

试试这个

SELECT email FROM email_table e 
LEFT JOIN contacted_table c ON e.email = c.email
WHERE c.email IS NULL

Try this

SELECT email FROM email_table e 
LEFT JOIN contacted_table c ON e.email = c.email
WHERE c.email IS NULL
深爱成瘾 2024-10-17 06:52:05
select email 
from Email_Table t1 
where not exists (select email 
                  from Contacted_table t2 
                  where t1.email = t2.email)

select email 
from Email_Table t1 
where email not in (select email 
                    from Contacted_table)
select email 
from Email_Table t1 
where not exists (select email 
                  from Contacted_table t2 
                  where t1.email = t2.email)

OR

select email 
from Email_Table t1 
where email not in (select email 
                    from Contacted_table)
指尖微凉心微凉 2024-10-17 06:52:05

如果您尝试像这样进行左连接:

SELECT users.email, contacted.email
FROM users LEFT JOIN contacted ON users.email = contacted.email

您将得到类似的结果:

users.email | contacted.email
-----------------------------
[email protected]   | [email protected]
[email protected]   | [email protected]
[email protected]   | [email protected]
[email protected]   | NULL
[email protected]   | NULL

您的目标是获取那些在 contacted 表中没有匹配项的记录,因此您的查询将是:

SELECT users.email
FROM users LEFT JOIN contacted ON users.email = contacted.email
WHERE contacted.email IS NULL

If you try to do a left join like this:

SELECT users.email, contacted.email
FROM users LEFT JOIN contacted ON users.email = contacted.email

You will get a similar result:

users.email | contacted.email
-----------------------------
[email protected]   | [email protected]
[email protected]   | [email protected]
[email protected]   | [email protected]
[email protected]   | NULL
[email protected]   | NULL

Your goal is to get those record which do not have a match in the contacted table, so your query would be:

SELECT users.email
FROM users LEFT JOIN contacted ON users.email = contacted.email
WHERE contacted.email IS NULL
九局 2024-10-17 06:52:05

删除电子邮件_表
FROM email_table INNER JOIN 联系
ON email_table.email_id = contacted.email_id;

DELETE email_table
FROM email_table INNER JOIN contacted
ON email_table.email_id = contacted.email_id;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文