Using 10.2.2 I am attempting to compare two fields in an attribute table using the Field Calculator. I'd like to return a value of '0' if they are equal and a value of '1' if they are not equal.

There are 600,000 records to compare and the overwhelming majority will end up being equal. So, in essence this is an exercise to identify the minority that are not equal.

  • you can create a simple selection "Field a" = "Field b" > calculate your "fields c" to 0 then reverse selection, calcutate "fields c" to 1 Dec 8, 2015 at 19:41
  • if you want just not equal value, select "Field a" <> "Field b" Dec 8, 2015 at 19:42

3 Answers 3


You can use this line in "Select by Attributes" Field1 <> Field2. This will select all where they are not equal, then field calculate a 1 into a column.


You can use a one liner code as follows: 1 if !field1! == !field2! else 0 Do not forget to select the 'python' radio button as opposed to the 'VB' in the field calculator

  • 1
    Didn't even use the code block. I love it! This saved me. Feb 15, 2019 at 0:21

You could define a function in python/vb. Check 'Show Codeblock' and a script similar to the one below could be used. In the pre-logic Script code, type:

def check(field1, field2):
    if field1==field2:
        return 0
        return 1

And in the new field, type in:


    check(!yourfield1!, !yourfield2!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.