在 SQL Server 中查找丢失的电子邮件
我正在尝试做一些我已经做过一百万次的事情,但它不起作用,有人能告诉我为什么吗?
我有一张表格,供发送简历的人使用,其中有他们的电子邮件地址...
我想查明这些人中是否有人尚未在该网站上注册。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
exists
而不是in
,如下所示:您应该获得更好的性能并避免“奇怪”的行为(我怀疑这与空值/结果有关)使用
in
。You could use
exists
instead ofin
like this:You should get better performance and avoid the 'weird' behaviour (which I suspect is to do with null values/results) when using
in
.另请参阅从一个表返回不在另一表中的所有行的五种方法
Also see Five ways to return all rows from one table which are not in another table
你可能有很多重复的东西。 我没有看到查询错误,但您可以尝试这样编写:
您也可以在其中添加 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:
You might also throw a GROUP BY or DISTINCT in there to get rid of duplicates.
最近我们遇到了一个非常类似的问题,子查询有时返回空值。 然后, in 语句以一种奇怪的方式对待 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:
it may work....