Excerpted from the advanced Google Sheets course, Data Analysis the Lazy Way.

There comes a time in every life, where you want to combine two data ranges within a Google Sheets query.

Let’s talk about how to combine data ranges from within the same spreadsheet (or from two different sheets), to run one query - working through examples using sample Twitter data.

To query a combined range from within the same sheet:

=query({tweets!A:D, ‘tweets 2’!A2:D}, “select Col3, count(Col2) where Col2 != ‘’ group by Col3”)

1. Enclose both ranges within { } to combine them, and separate with a ‘;’ to stack one on top of the other
2. Instead of referencing columns with their letter (A, B), refer to them as Col1, Col2 depending on their order

To query a combined range from different sheets:

1. First run the importrange function on the outside Sheet you’d like to pull from. The first element is the spreadsheet ID, which is contained within the URL of the sheet.
2. You’ll be asked to allow access to the sheet.
3. Embed the range from your importrange function within the query itself.

To be honest, my goal is to never have to combine ranges from within a query itself (I prefer to do that type of aggregation before writing a query), but sometimes it’s unavoidable.

For more background on all of the QUERY syntax covered in this video, grab a copy of my Google Sheets formula cheat sheet at: https://trello.com/c/b2q3P0...