Search code examples
stringgoogle-sheetsgoogle-sheets-formulawhere-clausegoogle-query-language

QUERY function, containing string in the WHERE clause


I would like to copy and paste data from cells in columns A:D in sheet 1, onto sheet 2 only if the cells in Column F = yes

I have tried to write the formula, but I keep getting parse errors. The formula I have tried to use is

=query("Sheet1"!A:D,"Select A where F="Yes"")

Solution

  • I think your code was not working, because you did not include F in your data range, when you first defined it. And also the double quotes problem around Yes - there should be single quotes. This works for me:

    =query(Sheet1!A:F,"Select A Where F='Yes'")
    

    In case you want to return 4 columns:

    =query(Sheet1!A:F,"Select A, B, C, D Where F='Yes'")
    

    Also worth noting - the string search in the where clause of the query function works only if in the column you have more strings than any of the other formats.