function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ZarehZareh 

Select DISTINCT values

Hi All,
 
I am trying to do a SELECT DISTINCT values from one of our custom tables. The equivalent of
 
SELECT DISTINCT fieldA,fieldB from tableC
 
But it looks like there is no way to do this with the Salesforce API am I correct ? if yes then how can I run a query like this ?
 
Later on I will need to run a query to get the count of distinct values in a table,
I can do SELECT count() FROM tableA
but cant do SELECT DISTINCT count() FROM tableA
 
Thanks
RickyGRickyG
SOQL, which is used to query Force.com objects, does not support the DISTINCT keyword.  You can get to the same place by separating out the data you want to be unique, creating an object with the non-repeating data in a field designated unique, and then doing a lookup to the related object.

This post summarizes some of the other differences between SOQL and SQL.  Hope this helps.


Message Edited by RickyG on 02-01-2008 08:53 AM
ZarehZareh

Thank you very much Rick for your suggestion.

We will try this workaround, its just strange that we cant really do a simple thing like select distinct directly.

Cheers

Zareh

learnSFlearnSF

Could you please post some example for it.It seems little confuse to me.

I need distinct activity with one account in some peroid of time frame.

Suppose for one account I just want to know that that account is having call or not no matter how many time it has call log in one month peroid of time.

It would be great if you can show some exmaple like this.

-Thanks in advance

Karl DrahovskyKarl Drahovsky

Please allow Destinct.

 

Having a lookup is an option.

 

However, with regards to interfacing data, lots of times it is not lookups, just raw;  therefore the Select Distinct is justified.