Search code examples
sqlgoogle-sheetsgoogle-sheets-formulagoogle-query-language

Google Sheets Query: Select A,B,E WHERE E MATCHES X OR E MATCHES Y OR E MATCHES Z


So I have the following query:

=QUERY(Data!A1:J,"SELECT A,B,E WHERE E MATCHES 'UK > Maternity Leave' OR E MATCHES 'UK > Long Leave' OR E MATCHES 'UK > Career Break' OR E MATCHES 'UK > Extended Unpaid Leave' OR WHERE E MATCHES 'UK > Shared Parental Leave (Birth)'",1)

Which, as far as I can tell should work. But it is giving me the following error message:

Error Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "where" "WHERE "" at line 1, column 162. Was expecting one of: "true" ... "false" ... "not" ... "date" ... "timeofday" ... "datetime" ... "timestamp" ... "min" ... "max" ... "avg" ... "count" ... "sum" ... "no_values" ... "no_format" ... "is" ... "null" ... "year" ... "month" ... "day" ... "hour" ... "minute" ... "second" ... "millisecond" ... "with" ... "contains" ... "starts" ... "ends" ... "matches" ... "like" ... "now" ... "dateDiff" ... "quarter" ... "lower" ... "upper" ... "dayOfWeek" ... "toDate" ... ... <INTEGER_LITERAL> ... <DECIMAL_LITERAL> ... <STRING_LITERAL> ... <QUOTED_ID> ... "(" ... "-" ...

Here is a link to the sheet - SO Example Sheet

I can't see what I am doing wrong here. I have tried SELECT A, B, E and SELECT Col1, Col2, Col5 as I have had some weird errors with queries in sheets in the past due to that. If anyone can point out what is wrong, that would be amazing!


Solution

  • You have WHERE listed more than once, which looks like the issue.

    Instead:

    =QUERY(Data!A1:J,"SELECT A,B,E WHERE E MATCHES 'UK > Maternity Leave' OR E MATCHES 'UK > Long Leave' OR E MATCHES 'UK > Career Break' OR E MATCHES 'UK > Extended Unpaid Leave' OR E MATCHES 'UK > Shared Parental Leave (Birth)'",1)