How do I Google Sheets Query: Use Order By

Google Sheets Query is a powerful function that allows you to quickly filter and sort data from a range of cells in a spreadsheet. The Order By clause lets you control the order in which the results of a query are returned. It can be used to sort records in ascending or descending order based on a column or multiple columns. This is a great tool for sorting large datasets in a way that makes them easier to analyze and interpret.


You can use the following syntax to order the results of a Google Sheets Query by a certain column:

=query(A1:C12, "select A, B order by B asc", 1)

In this example, we select columns A and B and order the results by column B ascending. We also specify a 1 to indicate that there is 1 header row at the top of the dataset.

You can also use the following syntax to order by multiple columns:

=query(A1:C12, "select A, B order by B asc, A desc", 1)

In this example, we select columns A and B and order the results by column B ascending, then by column A descending.

The following examples show how to use these formulas in practice.

Example 1: Order By One Column Ascending

We can use the following formula to select the Player and Team columns, then order the results by Team in ascending order:

Example 2: Order By One Column Descending

We can use the following formula to select all of the columns and order the results by Points in descending order:

Google Sheets query order by one column

Example 3: Order by Multiple Columns

We can use the following formula to select all columns and order the results first by Team ascending, then by Points descending:

Google Sheets Query order by multiple columns

Google Sheets Query: How to Use Group By

x