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

Query to fetch Unique records

how can i create a soql to fetch unique ownerid from Account Object. i don't want to handle this in the code.

It is not possible in SOQL
You will have to carry out this in code
Thanks Sam,

but i need to do it in S-Control, how could i do it.

you can do something like this.


Array.prototype.contains = function (element)
          for (var i = 0; i < this.length; i++)
              if (this[i] == element)
                      return true;
          return false;

var uniqueArr = new Array();

var result = sforce.connection.query("SELECT OwnerId from Account");
var record = result.getArray("record");

for(var i = 0; i < record.length;i++) {
    if(!uniqueArr.contains(record[i].OwnerId)) {



//Now unique Arr contains all unique ownerIDs.
hi sham,

Thank u very much dear, now i am able to solve my problem.
but in java script array we can't add a element using add();
so i need to define another prototype for adding the element in array.
Array.prototype.add = function (element){
this[this.length] = element;

Again thanks :smileyhappy:
You can write aggreerate querry for this. Below is the link 

lIST<AggregateResult> listofAccountsAggregateResult = 
                            [SELECT Ownerid
                              FROM  Account
                              GROUP BY Ownerid];