I have two tables I am able to join like so:
select * from
(select * from table1 t1
left join table2 t2 on t1.id = t2.id )
I want to add a third table where I group by email, to back fill data in the join above but I only want to backfill the data for records that have an email count of 1 only. If there are duplicating email addresses for different records they should be excluded.
I Have been trying this query:
select * from
(select * from table1 t1
left join table2 t2 on t1.id = t2.id
inner join ((select email from table3 group by email
having count(*) =1) t3
on t3.email = t1.emailaddress)
At this point when I coalesce the email field with others in the bigger join I still see records back filled with data while having email counts greater than 1 being backfilled.
i.e
table from LEFT JOIN only:
email missing_id
a@a.com
b@b.com
table3 data ONLY
email missing_id
a@a.com 1
a@a.com 2
b@b.com 3
All tables joined where email only occurs once, should back fill the data in the left join like so:
email missing_id
a@a.com
b@b.com 3