在 SQL Server 中查找丢失的电子邮件

发布于 2024-07-04 07:25:46 字数 657 浏览 8 评论 0原文

我正在尝试做一些我已经做过一百万次的事情,但它不起作用,有人能告诉我为什么吗?

我有一张表格,供发送简历的人使用,其中有他们的电子邮件地址...

我想查明这些人中是否有人尚未在该网站上注册。 aspnet_Membership 表包含在网站上注册的所有人员。

有 9472 名求职者,拥有独特的电子邮件地址。

此查询产生 1793 个结果:

select j.email from jobseeker j
join aspnet_Membership m on j.email = m.email

这表明应该有 7679 (9472-1793) 封未在网站上注册的人的电子邮件。 由于其中 1793 个确实匹配,我希望其余的不匹配......但是当我对此进行查询时,我什么也没得到!

为什么这个查询没有给我任何信息???

select j.email 
from jobseeker j
where j.email not in (select email from aspnet_Membership)

我不知道这怎么可能行不通 - 它基本上是说“显示在 jobseeker 表中但不在 aspnet_Membership 表中的所有电子邮件......

I am trying to do something I've done a million times and it's not working, can anyone tell me why?

I have a table for people who sent in resumes, and it has their email address in it...

I want to find out if any of these people have NOT signed up on the web site. The aspnet_Membership table has all the people who ARE signed up on the web site.

There are 9472 job seekers, with unique email addresses.

This query produces 1793 results:

select j.email from jobseeker j
join aspnet_Membership m on j.email = m.email

This suggests that there should be 7679 (9472-1793) emails of people who are not signed up on the web site. Since 1793 of them DID match, I would expect the rest of them DON'T match... but when I do the query for that, I get nothing!

Why is this query giving me nothing???

select j.email 
from jobseeker j
where j.email not in (select email from aspnet_Membership)

I don't know how that could be not working - it basically says "show me all the emails which are IN the jobseeker table, but NOT IN the aspnet_Membership table...

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

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

发布评论

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

评论(4

眼藏柔 2024-07-11 07:25:46

您可以使用 exists 而不是 in ,如下所示:

Select J.Email
From Jobseeker j
Where not exists (Select * From aspnetMembership a where j.email = a.email)

您应该获得更好的性能并避免“奇怪”的行为(我怀疑这与空值/结果有关)使用in

You could use exists instead of in like this:

Select J.Email
From Jobseeker j
Where not exists (Select * From aspnetMembership a where j.email = a.email)

You should get better performance and avoid the 'weird' behaviour (which I suspect is to do with null values/results) when using in.

辞别 2024-07-11 07:25:46

你可能有很多重复的东西。 我没有看到查询错误,但您可以尝试这样编写:

SELECT j.email
FROM jobseeker j
LEFT JOIN aspnet_Membership m ON m.email = j.email
WHERE m.email IS NULL

您也可以在其中添加 GROUP BY 或 DISTINCT 以消除重复项。

You could have a lot of duplicates out there. I'm not seeing the query error off the top of my head, but you might try writing it this way:

SELECT j.email
FROM jobseeker j
LEFT JOIN aspnet_Membership m ON m.email = j.email
WHERE m.email IS NULL

You might also throw a GROUP BY or DISTINCT in there to get rid of duplicates.

日久见人心 2024-07-11 07:25:46

最近我们遇到了一个非常类似的问题,子查询有时返回空值。 然后, in 语句以一种奇怪的方式对待 null,我认为总是匹配该值,所以如果您将查询更改为:

select j.email 
from jobseeker j
where j.email not in (select email from aspnet_Membership
                      where email is not null)

它可能会工作......

We had a very similar problem recently where the subquery was returning null values sometimes. Then, the in statement treats null in a weird way, I think always matching the value, so if you change your query to:

select j.email 
from jobseeker j
where j.email not in (select email from aspnet_Membership
                      where email is not null)

it may work....

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