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
Jeff McJeff Mc 

Malformed SOQL query

The following query returns the error below and I'm not sure why.  If I remove the "AND (p.AccountToId != Opportunity.AccountId)" then it returns 2 rows.

SELECT p.OpportunityId, p.AccountToId, p.Role, p.IsPrimary, Opportunity.AccountId
FROM Partner p
WHERE (p.OpportunityId = 'XXXXXXX') AND (p.AccountToId != Opportunity.AccountId)

In the actual query 'XXXXXXX' is a valid ID

unexpected token: 'Opportunity.AccountId'

Any idea what I'm doing wrong?
Best Answer chosen by Jeff Mc
Damien Phillippi033905702927186443Damien Phillippi033905702927186443
You are trying to make SOQL behave like SQL.  The second part of a query Conditional statement must always be some sort of variable or constant that isn't part of the query.