Is it possible to compare the Child and Parent field values in a Single SOQL Relationship Query ?

say get me all contacts for an account which doesn't have same name as its parent account.

SELECT Contact.Id, Contact.Name, Account.Id, Account.Name
FROM Contact
WHERE Account.Id = 'xxxxxxxxxxx' AND
      Contact.Name <> Account.Name

or get me all opportunities for an account which has same LeadSource as Account

SELECT Id, LeadSource, Account.LeadSource
FROM Opportunity 
WHERE AccountId in : accIdSet AND 
LeadSource <> Account.LeadSource

I don't think so. The field expression in the where clause can include only 1 field name and not 2. It must be compared to a native value.


| improve this answer | |
  • Thanks @folkert for the answer. I have seen this link before. I should have made it clear in my question that i m looking for possible workarounds.. – Vamsi Krishna Sep 24 '14 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.