To concatenate columns in a Google Sheets QUERY, you cannot use a dedicated CONCATENATE function inside QUERY; instead, use the ampersand (&) operator or the CONCAT function within the SELECT clause. For example, =QUERY(A:C, "select A & ' ' & B where C = 'Yes'") combines columns A and B with a space, filtering rows where column C equals “Yes”. This works because QUERY accepts standard Google Sheets operators in its SELECT statement.
Why QUERY Doesn’t Have CONCATENATE
Google Sheets QUERY is based on the Google Visualization API Query Language, which is a SQL-like language designed for data retrieval and aggregation. It supports functions like SUM, AVG, COUNT, and logical operators, but it does not include string functions like CONCATENATE, LEFT, or RIGHT. The ampersand (&) is the closest equivalent, acting as a string concatenation operator directly in the query string. This is a common point of confusion because users expect QUERY to mirror all spreadsheet functions, but it only exposes a limited set.
How to Concatenate in QUERY: The & Operator
The simplest method is to use the ampersand within the SELECT clause. The syntax is: =QUERY(range, "select column1 & delimiter & column2"). The delimiter can be a literal string enclosed in single quotes (since the query itself is in double quotes). For example, with data in A1:B10 (first names in A, last names in B), you can write:
=QUERY(A1:B10, "select A & ' ' & B")– returns full names with a space.=QUERY(A1:B10, "select A & '-' & B")– returns names like “John-Smith”.=QUERY(A1:B10, "select A & B")– concatenates without any separator.
Note that the result is a single column. If you need to keep the original columns alongside the concatenated one, you can list both in the SELECT clause: =QUERY(A1:B10, "select A, B, A & ' ' & B").
Using CONCAT with QUERY (Limited)
The CONCAT function in Google Sheets takes exactly two arguments. In QUERY, you can use it similarly, but it only accepts two columns or values, not a delimiter. For instance: =QUERY(A1:B10, "select CONCAT(A, B)") will combine A and B with no separator. To add a space, you would need to nest it: =QUERY(A1:B10, "select CONCAT(CONCAT(A, ' '), B)"). However, the ampersand method is shorter and more readable, so CONCAT is rarely preferred in QUERY.
Common Pitfalls and Error Messages
One frequent issue is mixing single and double quotes. The QUERY function requires the query string to be in double quotes, and any literal text inside must use single quotes. For example, =QUERY(A1:B10, "select A & ' ' & B") is correct, but =QUERY(A1:B10, "select A & " " & B") will fail. Another pitfall is trying to concatenate a numeric column with text – QUERY treats numbers as numbers, so you may get unexpected results. To force text, you can use the TO_TEXT function (available in QUERY) on the numeric column: =QUERY(A1:B10, "select A & ' ' & TO_TEXT(B)") where B is numeric.
If you see a #VALUE! error, it often means the query syntax is invalid, often due to a missing closing quote or an incorrect column reference. Remember that column references in QUERY are letters (A, B, C) not numbers, and they refer to the columns in the range you specified, not the entire sheet.
Alternatives to QUERY for Concatenation
If QUERY feels restrictive, you can achieve the same result with other functions:
- ARRAYFORMULA with &:
=ARRAYFORMULA(A1:A10 & " " & B1:B10)– this fills the entire column without dragging. - CONCATENATE with ARRAYFORMULA:
=ARRAYFORMULA(CONCATENATE(A1:A10, " ", B1:B10))– but note CONCATENATE with arrays returns a single cell, so use & instead. - JOIN with SPLIT: If you have a list in one column, you can use
=JOIN(", ", A1:A10)to combine all values into one cell, but that’s not row-wise. - FILTER plus &: To concatenate only certain rows, you can combine FILTER with &, e.g.,
=FILTER(A1:A10 & " " & B1:B10, C1:C10="Yes").
The choice depends on whether you need filtering, aggregation, or just a simple column join.
Cost and Performance Considerations
Google Sheets is free for personal use, and QUERY is a standard function with no additional cost. However, performance can degrade with very large datasets (over 100,000 rows). Using QUERY with concatenation on large ranges may slow down recalculations. In such cases, consider using ARRAYFORMULA with &, which is often faster because it avoids the query parser overhead. For extremely large data, Google BigQuery is a paid alternative that supports SQL-like CONCAT, but that’s beyond Sheets.
Safety and Data Accuracy
When concatenating columns, be mindful of data types. If a column contains dates, they will appear as serial numbers unless formatted. Use TEXT function in QUERY to format dates: =QUERY(A1:B10, "select A & ' ' & TEXT(B, 'yyyy-mm-dd')") – but note TEXT inside QUERY may not work as expected; instead, format the date column first using the Format menu. Also, be careful with leading/trailing spaces in cells – use TRIM within the query if needed: =QUERY(A1:B10, "select TRIM(A) & ' ' & TRIM(B)"). Always test on a small sample before applying to your entire dataset.
Frequently Asked Questions
Can I use CONCATENATE inside QUERY?
No, the QUERY language does not support the CONCATENATE function. Use the ampersand (&) operator instead, which works exactly like CONCATENATE for two or more values.
How do I concatenate with a comma and space in QUERY?
Use the ampersand with a literal string: =QUERY(A1:B10, "select A & ', ' & B"). The comma and space are inside single quotes.
Why does my QUERY return #VALUE! when I try to concatenate?
This usually means a syntax error, often from using double quotes inside the query string. Ensure all literal text uses single quotes, and the entire query is in double quotes. Also check that column references are correct for your range.
Can I concatenate more than two columns in QUERY?
Yes, you can chain ampersands: =QUERY(A1:C10, "select A & ' ' & B & ' ' & C"). There is no limit to the number of columns you can combine.
Does QUERY concatenate numbers as text or numbers?
By default, numbers remain numeric, so concatenating a number with text may produce unexpected results. Use TO_TEXT() on numeric columns to force them to text: =QUERY(A1:B10, "select A & ' ' & TO_TEXT(B)").
Is there a way to concatenate with a line break in QUERY?
Yes, use the CHAR function with code 10: =QUERY(A1:B10, "select A & CHAR(10) & B"). This inserts a line break, but you may need to enable wrapping in the cell.
Related
- Shortcut to Switch Off Computer: Fastest Ways
- Generate Random Number in Unity: C# Script Guide
- Free Data Entry Software for Windows 10: 7 Real Options
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Why Did My Outlook View Just Change?Your Outlook view usually changes because a display setting was switched, a different folder has its own view,…
- Delete an Unused Page in Word: Causes and Easy FixesTo delete an unused page in Microsoft Word, show formatting marks with Ctrl+Shift+8, then remove the extra paragraph…
- Excel Shortcut to Select a RowIn Excel for Microsoft 365 on Windows, press Shift+Spacebar to select the entire worksheet row containing the active…
- Google Sheets: Show Percentages to 2 Decimal PlacesTo show percentages with two decimal places in Google Sheets, select the cells and choose Format > Number…
- Can You Split a Cell in Google Sheets? Here’s HowYes, you can split the text in a Google Sheets cell into separate columns using Data > Split…
- How to Set an Out of Office Reply in Outlook 365To set an out of office reply in Outlook 365, open Automatic Replies, switch them on, write your…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.