Google Sheets – How to Add Column BY to a Query

google sheetsgoogle-sheets-query

How do I include the column BY in a query?
I first tried =unique(query(data_table,"SELECT D, BY"))

Then, I tried to surround it with single quotes =unique(query(data_table,"SELECT D, 'BY'"))

Best Answer

Short answer

Put BY column identifier between back quotes, =unique(query(data_table,"SELECT D, `BY`"))

Explanation

BY is a Google Query Language keyword. From https://developers.google.com/chart/interactive/docs/querylanguage#Identifiers

Identifiers

Identifiers (or IDs) are text strings that identify columns.

Important: If your identifier

  • Has spaces,
  • Is a reserved word,
  • Contains anything but alphanumeric characters or underscores ([a-zA-Z0-9_]), or
  • Starts with a digit

it must be surrounded by back-quotes (not single quotes).