 select distinct bipr.account_record_id
 from analytics_payment_refunds bipr
 left outer join invoice_payments ip on ip.id = bipr.invoice_payment_id
-where coalesce(ip.record_id, 'NULL') != coalesce(bipr.invoice_payment_record_id, 'NULL')
+where (coalesce(ip.record_id, 'NULL') != coalesce(bipr.invoice_payment_record_id, 'NULL')
 or coalesce(ip.id, 'NULL') != coalesce(bipr.invoice_payment_id, 'NULL')
 or coalesce(ip.invoice_id, 'NULL') != coalesce(bipr.invoice_id, 'NULL')
 or coalesce(ip.type, 'NULL') != coalesce(bipr.invoice_payment_type, 'NULL')

select distinct bip.account_record_id
from analytics_payment_purchases bip
left outer join invoice_payments ip on ip.id = bip.invoice_payment_id
where coalesce(ip.record_id, 'NULL') != coalesce(bip.invoice_payment_record_id, 'NULL')
or coalesce(ip.ID, 'NULL') != coalesce(bip.invoice_payment_id, 'NULL')
or coalesce(ip.invoice_id, 'NULL') != coalesce(bip.invoice_id, 'NULL')
or coalesce(ip.type, 'NULL') != coalesce(bip.invoice_payment_type, 'NULL')

or coalesce(ip.created_date, 'NULL') != coalesce(bipr.created_date, 'NULL')
or coalesce(ip.account_record_id, 'NULL') != coalesce(bipr.account_record_id, 'NULL')
or coalesce(ip.tenant_record_id, 'NULL') != coalesce(bipr.tenant_record_id, 'NULL')
or bipr.invoice_payment_type != 'REFUND')
and bipr.invoice_payment_record_id!=0
;

select 'H2' as sanity_query_name;
