Assuming I have two tables, one with the following columns called lease_period:
tenant_trading_name, suite_id, lease_id, building_id
and another, called lease_period_audit with the following:
audit_date, audit_type, tenant_trading_name, suite_id, lease_id, building_id
Each time a record is updated on lease_period and entry is made on lease_period_audit with a status of 'Updated'. I'm trying to find all updates made only to the tenant_trading_name field but haven't had any success. So far I have the following:
select lpa.*
from property.lease_period_audit lpa
inner join property.lease_period lp on lpa.suite_id = lp.suite_id and lpa.lease_id = lp.lease_id and lpa.building_id = lp.building_id
where audit_type = 'Updated'
and lp.tenant_trading_name <> lpa.tenant_trading_name
order by 1 desc
Where's the flaw in my thought process here? How can this be done / how should I be thinking about this?