从另一个表中获取丢失的数据

时间:2018-09-28 17:40:07

标签: sql oracle

我有两个表“ Admission”和“ EmailAddress”。在录取过程中,如果有人注册了“ paperlessCommunication”,则系统应将其电子邮件添加到EmailAddress表中。由于某些编码错误,一些注册了“ paperlessCommunication”的准入者在emailAddress表中缺少了电子邮件地址。我如何找到所有签署了无纸化通信但在电子邮件地址中缺少记录的记录... P.S.电子邮件地址表也包含来自其他一些过程的电子邮件地址,我只是对录入过程中缺少的将无纸化标志设置为“ Y”的电子邮件地址感兴趣。

select * from Admission a where a.paperlessCommunication = 'Y'

select * from EmailAddress

两个表都有“ personid”列。

2 个答案:

答案 0 :(得分:2)

一种方法是command "aws s3 sync s3://#{node['Bucket']}/ /prod/users/myfiles/"

not exists

这假定电子邮件地址在两个表中。如果不是这样,肯定会使用其他一些id来代替。

答案 1 :(得分:1)

有几种解决方案

解决方案#1

select *
from Admission A
where paperlessCommunication = 'Y' 
and not exists (select 1 from EmailAddress ea where ea.emailaddress = A.emailaddress);

解决方案2

select *
from Admission A
where paperlessCommunication = 'Y' 
and emailaddress not in (select emailaddress from EmailAddress where emailaddress is not null);

解决方案3

select *
from Admission A
left join EmailAddress EA on Em.emailaddress  = A.emailaddress 
where paperlessCommunication = 'Y' 
and EA.emailaddress is null