Search code examples
google-sheetsgoogle-sheets-formula

Google Sheets Queries help using OR AND better


I've been trying for ages to find a more elegant solution to my queries ... instead of

"Select * where not Col42 contains '#CBCno' and not Col42 contains '#CBCnever' and not Col42 contains '#noCBC' and not Col42 contains '#CBClead'"

Is there any way to list multiple conditions in one so it's easier to change? For example:

"Select * where not Col42 contains ('#CBCno' OR '#CBCnever' OR '#noCBC' OR '#CBClead')"

I've googled it multiple times and tried various brackets with OR ideas but none worked so far... closest I came was finding I can use MATCHES '(#CBCnever|#CBCno)' but i need to use 'contains' not find exact matches :(

can anyone help (or put me out of my misery)?


Solution

  • Use the matches keyword:

    "where not Col42 matches '.*(#CBCno|#CBCnever|#noCBC|#CBClead).*'"
    

    enter image description here