1

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)

1

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.

Source: https://developers.google.com/chart/interactive/docs/querylanguage#select

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.

0

If you only need to make a column to appear twice, instead of QUERY use an array.

={B3:B7,C3:C7,B3:B7}

If you will do some more complex, you could use the above array as the first argument of QUERY, but doing so, instead of using A, B, C notation for columns, use Col1, Col2, Col3.

Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.