Google-sheets – How to select column twice in query

google sheetsgoogle-sheets-query

I have a query that is really long (about 50 columns), I don't want to split into 2 queries. But I want a column to show up twice. Is there a way to do this? below is a simple example that doesn't work.

How to select B twice? The ability to select something twice is pretty standard in any SQL right?

=query(B3:D7,"select B,C,B",0)

Best Answer

According to Google Help, the selected column must be an identifier, so it seems select a column twice is not possible within google query language.


However, if your query is not too complex, you can cheat using aggreagation operators.

If your column B is a number:

=query(B3:D7,"select B,C,B+0",0)

If your column B is a string:

There is no neutral operator, but upper or lower can be usefull if the case isn't an issue for you.

=query(B3:D7,"select B,C,UPPER(B)",0)

If you use label, you'll have to respect the same identifier syntax used in your select clause.