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
Deepu sfdcDeepu sfdc 

I want to get accounts from org where mailing city and billing city is same.. How to write query for this ?

Best Answer chosen by Deepu sfdc
Not possible in one single query
Salesforce does not allow direct field to field comparison in SOQL query.
To achieve this you may create a formula field that will compare fields and return a value (like true or false) which you may use in a WHERE clause.

So for the above query, you could create a formula field on User object with return type Text e.g. NameCompare, with the formula
IF(User.FirstName != User.LastName, 'true', 'false')
Now our query will be:
List<User> Users = [SELECT id, name FROM User where NameCompare= 'true'];
Following idea has been posted on ideaexchange portal for allowing field-to-field comparison in SOQL: