+ Start a Discussion
MarkInAtlantaMarkInAtlanta 

SOQL using a relationship in a where clause?

Scratching my head on this one.  Want to find accounts whose owner is different than its parent account. 

throws a parsing syntax  error  when i compare the 2 fields, although i can compare  them individualy..
  
Query works fine without the Where clause, just wahay too many returns to efficiently process them.

Select  Id,  OwnerId , Parent.OwnerId  From Account 
where   OwnerId  !=  Parent.OwnerId  
Best Answer chosen by MarkInAtlanta
Chris  ByromChris Byrom
SOQL does not support direct field comparison. You can create a formula field to do the comparison for you, and then query based on the result of the field. This is a system limitation.

http://help.salesforce.com/HTViewSolution?id=000187460

All Answers

Chris  ByromChris Byrom
SOQL does not support direct field comparison. You can create a formula field to do the comparison for you, and then query based on the result of the field. This is a system limitation.

http://help.salesforce.com/HTViewSolution?id=000187460
This was selected as the best answer
PavanKPavanK
Thanks for posting question.

Unfortunately, you can not use field comparison in where clause.

But one easy solution is, create formula field on child object and mark it as false if owner is not matching.

Then use this field in query as where clause.

Please mark this answer as best if my reply helped.
MarkInAtlantaMarkInAtlanta
thank you all..   no wonder i couldn't find an example..