+ 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

MALFORMED_QUERY
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.