+ Start a Discussion
Seth PayneSeth Payne 

SOQL Query to compare show all Contacts with different Owner than Account owner

Hi,
I am trying to create a query that shows me all the contact owner and account owner are different.

Here is what I have now:
 
Select Id, AccountId, OwnerID, Acccount.OwnerId 
    FROM Contact 
    WHERE OwnerId != Account.OwnerID


Here is the error i am receving in Query Editor:
Unknown error parsing query

I am assuming this is because one of them is polymorphic and can be user or queue.  Any thoughts are a work around for this query?

 
Saikishore Reddy AengareddySaikishore Reddy Aengareddy
Create a formulae field on contact object called "Is_Same_Owner__c" and return type as checkbox with the formula Account.Owner.Id = OwnerId
And You can use query something like..

select Id, AccountId, ownerid, account.ownerid from contact where is_Same_Owner__c = false
 
Shaijan ThomasShaijan Thomas
As per my understanding this is not possible. you are trying to compare two values with in the record. its not possible
Shaijan