Jim C. Nasby wrote:
...
> No, this can certainly be done in SQL, though if you have pseudo or ruby
> code on how you'd do it, it might make it a bit more clear on what
> you're after.
...
I managed to find a suitable solution for this:
(I am using postgres 7.4)
SELECT property_id, address FROM marketing_campaigns
LEFT JOIN properties ON properties.id = marketing_campaigns.property_id
WHERE address LIKE *?
GROUP BY property_id, address
HAVING count(ended_on) = **count(1)
* variable
** apparently count(1) is faster than count(*) and count(id), my Rails log
confirms this, however I have a limited amount of records at the moment so
benchmarks are properly inaccurate..