Search code examples
google-sheetsgoogle-query-language

Can someone help explain the syntax behind this query in Google Sheets?


I recently came across this query on Google Sheets and I had a question about one of these queries:

=transpose(query(settings!A2:C,"select B, C where A = '" & B4 & "'",0))

Could some explain to me this section?

= '" & B4 & "'",0)

I am struggling to find documentation that can help explain how the ' and " work in Google Sheets queries.


Solution

  • It is creating a query string using a cell value.

    Say you had the word Simon in cell B4 then it is constructing

    "select B, C where A = '" & B4 & "'"
    

    as

    Select B, C where A = 'Simon'
    

    The & operator concatenates (combines) strings. Here is is adding the value of cell b4 into your where clause.