I have 3 tables with email address and contact details and I want to produce one list from all 3 with no duplicate email addresses with a preference to keeping the record from the first database.
I've used union distinct but that only gives me distinct rows not distinct email addresses i.e.
table1
fred@ibm.com, fred, Y
john@ibm.com, john, Y
table2
fred@ibm.com, fred, N
john@ibm.com, jonny, N
table3
bob@ibm.com, bob, N
just using a union distinct
select EML, FN, 'Y' Z from table1
union distinct
select EML, FN, 'N' Z from table2
union distinct
select EML, FN, 'N' Z from table3
order by Z DESC
gives me
fred@ibm.com, fred, Y
john@ibm.com, john, Y
fred@ibm.com, fred, N
john@ibm.com, jonny, N
bob@ibm.com, bob, N
but I only want distinct email addresses not rows with a preference to keeping the record on table1 as below
fred@ibm.com, fred, Y
john@ibm.com, john, Y
bob@ibm.com, bob, N
Any help would be appreciated