Wat dacht je van een join
? Het volgende toont alle paren die verschillend zijn:
select tb.*, ts.*
from company tb join
company ts
on tb.company_name = ts.company_name and
ts.address_type = 'shipping' and
tb.address_type = 'billing' and
ts.address <> tb.address;
Als u alleen de bedrijven wilt die anders zijn:
select company_name
from company t
group by company_name
having count(distinct case when t.address_type = 'billing' then address end) = 1 and
count(distinct case when t.address_type = 'shipping' then address end) = 1 and
(max(case when t.address_type = 'billing' then address end) <>
max(case when t.address_type = 'shipping' then address end)
);
Let op:hiermee wordt ook gecontroleerd of er maar één duidelijk factuur- en verzendadres is.