2

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)

2 Answers 2

4

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

2
  • But this syntax is for vertical combination, not columns side to side. me wrong? OK, difference between ; and ,
    – Sandburg
    Apr 28 at 15:11
  • I'm sorry, I don't understand your comment. Are you trying to say my answer is unclear? Have you already read the reference?
    – Rubén
    Apr 28 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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