We have an object that relates to Account (Services). I'm trying to write a SOQL query that can give me accounts that have at least one active such object. Those objects have a checkbox that is checked when inactive. A single account can have dozens of these objects, inactive or not but I'm only interested in getting a list of Accounts that have at least one active.
I'm thinking something like
[SELECT id, account__r.id, account__r.name from service__c where cb_IsInactive = false]
But this returns me all active services by account. Can I add a filter into this query that only gives me one line per account? Some thing like COUNT() but of course not the same?
Edit: After hitting what I think are governor limits to my query I noticed the new (or semi-new) COUNT_DISTINCT aggregate query. This returned me the total distinct number of accounts, and the rest was done by query all active services as csv, importing to Excel and using the filter functions there to eliminate duplicates.
EDIT2: This here query worked for me, for anyone that has the same or similar problem
select COUNT_DISTINCT(Account__r.Id) from Service__c where chk_Inactive__c =false