I have subscriptions table that looks roughly:
id (auto generated id)
I would like to find records that:
A) are of different company (company id) but have same city/state
B) are of different company (company id) but have same subscription date
For address, I was doing:
select distinct on (t1.company_id) t1.company_id, t2.company_id, t1.city, t1.state from subscription t1, subscription t2 where t1.company_id <> t2.company_id and t1.city = t2.city and t1.state = t2.state order by t1.company_id
Is this efficient and accurate way to do it?