1

I'm using ArcMap and am trying to filter a selection from my attribute table that contains both NULL and regular values but it is not working.

The query should only select John values with NULL, Addition, and Construction. Below I did my best but the NULL are not helping. What is the solution?

Select * FROM Table_name WHERE:
Usr_name ='John' AND Project_name IS NULL OR Project_name IN ('Addition', 'Construction')

Input

Object_ID   Object_type Usr_name    Project_name
 1            Triangle    John         Addition
 2             Square     Peter        Addition
 3            Polygon     Mary         Addition
 4             Circle     John       Substracion
 5            Polygon     Mary          <Null>
 6             Square     Mary          <Null>
 7             Square     John          <Null>
 8            Polygon     John         Obstacle
 9              Hex       John       Construction

The minimal desired output result

Object_ID   Object_type Usr_name    Project_name
  1           Triangle    John        Addition
  7            Square     John         <Null>
  9             Hex       John      Construction
1
  • 1
    The order of precedence for the OR operator is rarely what you think it is. Whenever you have an OR, make sure you have explicit parenthesis. – Vince May 9 '20 at 2:32
3

When a selection statement doesn't behave as you expect, it may be because of the order in which the sub-expressions are evaluated. You can override that order by adding extra parenthesis. In your case it should probably look like:

Select* FROM Table_name WHERE:
Usr_name ='John' AND (Project_name IS NULL OR Project_name IN ('Addition', 'Construction'))
1
  • Thanks! This worked. – Zesima29 May 11 '20 at 11:55

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.