3

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

1 Answer 1

5

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.

http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_fieldexpression.htm#fieldexpression

1
  • 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.. Commented Sep 24, 2014 at 22:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .