1

I am trying to query several different colors from one column. This is what I have so far:

=query('Raw Data'!C1:J1000,
"Select E, D, I, J, C, F, H 
  where H contains 'Monday' 
  and F='Green' 
  and C='schools' 
  order by E")

For example I want to query all the items that are Green, Red, and Blue in the F column. Is there a way to query for multiple selection in 1 column?

0

Two way to do this with a Query.

  1. With a regular expression and matches :

     =query('Raw Data'!C1:J1000,
     "Select E, D, I, J, C, F, H 
       where H contains 'Monday' 
       and F matches 'Red|Green|Blue' 
       and C='schools' 
       order by E")
    

matches - A (preg) regular expression match. haystack matches needle is true if the regular expression in needle matches haystack. Examples: where country matches '.*ia' matches India and Nigeria, but not Indiana. Note that this is not a global search, so where country matches 'an' will not match 'Canada'.


Source : Query Language Reference

  1. With classical logic and boolean :

     =query('Raw Data'!C1:J1000,
     "Select E, D, I, J, C, F, H 
        where H contains 'Monday' 
        and (F='Green' or F='Red' or F='Blue')
        and C='schools' 
        order by E")
    

You can join multiple conditions using the logical operators and, or, and not. Parentheses can be used to define explicit precedence.

Same source

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.