How to select Unique values in SOQL distinct?
I am trying to get unique values by Territory_ID__c with a (Salesforce SQL) SOQL query.
I tried this:
return [select id,name,ANNUAL_CALLS__c,city__c,state__c,No_Of_Targets__c, Territory_ID__c,Territory__r.name,Territory__r.ANNUAL_CALLS__c from zip__c where name in :sArr unique by Territory_ID__c];
But this does not return the unique values. How can I get unique values of a column?
An alternative to selecting soql distinct rows:
SELECT name, COUNT(Id) FROM Lead GROUP BY name
Shows you all of the distinct names, with how many of them there are.
One drawback is if there are too many rows in the table, it will just fail, just like sales force is in an existential way.