What is wrong with this SOQL ?

  1. SELECT Id, Name, Sales_Group_Code__c FROM Sales_Group__c WHERE Sales_Group_Code__c = Name

  2. SELECT Id, Name, Sales_Group_Code__c FROM Sales_Group__c WHERE Sales_Group_Code__c != Name

This gives results :

SELECT Id, Name, Sales_Group_Code__c FROM Sales_Group__c
| improve this question | | | | |
  • Do both 1st and 2nd queries are giving same results as you are getting from the last query? – itzmukeshy7 May 9 '17 at 11:56
  • 4
    In SF developer console the query 1 & 2 are not valid : "Unknown error parsing query" you can't have a where condition based on field comparaison in SOQL I think... – benahm May 9 '17 at 12:02
  • I am getting "Unknown error parsing query" when running queries 1,2. Is there a workaround to get this query result in developer console ? Will queries 1,2 work in workbench ? – Walker May 9 '17 at 12:04
  • 1
    Possible duplicate: salesforce.stackexchange.com/questions/137265/2995. Note that you can just write a checkbox formula to do the comparison, then filter on that instead. – Adrian Larson May 9 '17 at 12:36

SOQL is a subset of SQL

In the where clause you can only have a fieldName compared to a static value

Please refer to the SOQL documentation fieldExpression Syntax

The field expression syntax of the WHERE clause in a SOQL query consists of a field name, a comparison operator, and a value that’s used to compare with the value in the field name. fieldExpression uses the following syntax:

fieldName comparisonOperator value

| improve this answer | | | | |

You could add a formula field on the object to mark whether the name and sales code are the same, and then base your query on that.

Otherwise I don't think you can filter in a where clause the way you are trying to do it.

| improve this answer | | | | |

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.