Beginner 7 min read

QUERY ORDER BY in Google Sheets (Sort Results)

Learn how to use QUERY ORDER BY in Google Sheets to sort results by one or multiple columns, ascending or descending. Step-by-step examples.

SB

Sheets Bootcamp

April 30, 2026

QUERY ORDER BY in Google Sheets sorts the rows returned by your QUERY function in ascending or descending order. It works on text, numbers, and dates, and you can sort by multiple columns at once. We’ll cover the syntax, single and multi-column sorting, and how ORDER BY combines with WHERE and GROUP BY.

In This Guide

ORDER BY Syntax

ORDER BY goes at the end of the query string (before LIMIT, if used):

Formula
=QUERY(data, "SELECT columns ORDER BY column ASC|DESC")
KeywordMeaningExample
ASCAscending (A-Z, 0-9, oldest to newest)ORDER BY F ASC
DESCDescending (Z-A, 9-0, newest to oldest)ORDER BY F DESC
Note

ASC is the default. If you omit ASC or DESC, QUERY sorts ascending. ORDER BY F and ORDER BY F ASC produce the same result.

How to Sort QUERY Results: Step-by-Step

We’ll use the same sales records table from the QUERY guide. The data is in A1:G11 with 10 transactions.

Sample Data

ABCDEFG
1DateSalespersonRegionProductUnitsRevenueCommission
21/5/2026Fred WeasleyDiagon AlleyExtendable Ears12$239.88$24.00
31/7/2026Ginny WeasleyHogsmeadeSelf-Stirring Cauldron8$360.00$36.00
41/8/2026Lee JordanDiagon AlleyRemembrall15$525.00$52.50
51/10/2026Fred WeasleyDiagon AlleyOmnioculars5$325.00$32.50
61/12/2026George WeasleyHogsmeadeSneakoscope20$570.00$57.00
71/14/2026Ginny WeasleyHogwartsNimbus 200025$624.75$62.50
81/15/2026Lee JordanHogsmeadeExtendable Ears10$199.90$20.00
91/18/2026Fred WeasleyDiagon AlleyInvisibility Cloak3$269.97$27.00
101/20/2026George WeasleyHogwartsFirebolt8$336.00$33.60
111/22/2026Ginny WeasleyHogsmeadeDeluminator6$330.00$33.00

Sales records table with 10 transactions in Google Sheets

1

Review your data range

Your data lives in A1:G11. Row 1 is the header. Columns are Date (A), Salesperson (B), Region (C), Product (D), Units (E), Revenue (F), and Commission (G).

2

Sort by one column ascending

Select an empty cell and enter:

Formula
=QUERY(A1:G11, "SELECT B, D, F ORDER BY F ASC")

This returns Salesperson, Product, and Revenue sorted from lowest to highest revenue. Lee Jordan’s Extendable Ears ($199.90) appears first, and Ginny Weasley’s Nimbus 2000 ($624.75) appears last.

QUERY ORDER BY sorting revenue ascending showing 10 rows

3

Sort by one column descending

Change ASC to DESC:

Formula
=QUERY(A1:G11, "SELECT B, D, F ORDER BY F DESC")

Now the highest revenue appears first. Ginny Weasley’s Nimbus 2000 ($624.75) is row 1, and Lee Jordan’s Extendable Ears ($199.90) is last.

QUERY ORDER BY sorting revenue descending showing 10 rows

4

Sort by multiple columns

Enter:

Formula
=QUERY(A1:G11, "SELECT C, B, F ORDER BY C ASC, F DESC")

This sorts by Region alphabetically first. Within each region, rows are sorted by Revenue from highest to lowest. Diagon Alley’s top transaction (Lee Jordan, $525.00) appears before Diagon Alley’s lowest (Fred Weasley, $239.88).

QUERY ORDER BY sorting by region then revenue descending

Tip

Multi-column sorting is useful for reports. Sort by category first, then by amount within each category, to make the data scannable.

Sort Descending with DESC

DESC reverses the sort order. For numbers, it sorts largest to smallest. For text, Z to A. For dates, newest to oldest.

Formula
=QUERY(A1:G11, "SELECT B, E ORDER BY E DESC")

This returns Salesperson and Units sorted by Units descending. Ginny Weasley’s 25-unit transaction appears first.

Sort by Multiple Columns

Separate columns with commas. Each column can have its own sort direction:

Formula
=QUERY(A1:G11, "SELECT B, C, F ORDER BY B ASC, F DESC")

This sorts alphabetically by Salesperson. Fred Weasley’s rows appear first (because F comes before G, G, and L). Within Fred’s rows, the highest revenue transaction appears at the top.

You can sort by as many columns as you need. The first column takes priority, then the second breaks ties, and so on.

ORDER BY with WHERE

WHERE filters rows. ORDER BY sorts whatever WHERE returns.

Formula
=QUERY(A1:G11, "SELECT B, D, F WHERE C = 'Hogsmeade' ORDER BY F DESC")

This returns only Hogsmeade transactions, sorted by Revenue descending. George Weasley’s Sneakoscope ($570.00) appears first, followed by Ginny Weasley’s Self-Stirring Cauldron ($360.00), Ginny Weasley’s Deluminator ($330.00), and Lee Jordan’s Extendable Ears ($199.90).

QUERY ORDER BY with WHERE filtering Hogsmeade and sorting by revenue

Important

Clause order matters. WHERE must come before ORDER BY in the query string. Writing ORDER BY F DESC WHERE C = 'Hogsmeade' causes an error.

ORDER BY with GROUP BY

When you aggregate data with GROUP BY, ORDER BY sorts the grouped results:

Formula
=QUERY(A1:G11, "SELECT C, SUM(F) GROUP BY C ORDER BY SUM(F) DESC LABEL SUM(F) 'Total Revenue'")

This groups revenue by region, then sorts so the highest-revenue region appears first. Hogsmeade ($1,459.90) tops the list, followed by Diagon Alley ($1,359.85) and Hogwarts ($960.75).

QUERY ORDER BY with GROUP BY sorting regions by total revenue

To sort grouped results by the grouped column instead:

Formula
=QUERY(A1:G11, "SELECT C, SUM(F) GROUP BY C ORDER BY C ASC LABEL SUM(F) 'Total Revenue'")

This sorts regions alphabetically: Diagon Alley, Hogwarts, Hogsmeade.

Sort by Date

ORDER BY handles dates natively. No special syntax needed — the column’s data type determines how QUERY sorts:

Formula
=QUERY(A1:G11, "SELECT A, B, F ORDER BY A DESC")

This sorts transactions by date from newest to oldest. The 1/22/2026 transaction appears first, and the 1/5/2026 transaction appears last.

To get the most recent 3 transactions, combine ORDER BY DESC with LIMIT:

Formula
=QUERY(A1:G11, "SELECT A, B, F ORDER BY A DESC LIMIT 3")

This returns only the 3 most recent transactions: 1/22/2026 (Ginny Weasley, $330.00), 1/20/2026 (George Weasley, $336.00), and 1/18/2026 (Fred Weasley, $269.97).

QUERY ORDER BY date descending with LIMIT 3

Common Mistakes

Putting ORDER BY before WHERE

The clause order in QUERY is fixed: SELECT, WHERE, GROUP BY, PIVOT, ORDER BY, LIMIT, OFFSET, LABEL, FORMAT. Writing ORDER BY before WHERE causes a parse error.

Sorting by a column not in SELECT

ORDER BY can reference any column in the data range, even if it is not in the SELECT list. This is valid: SELECT B, F ORDER BY C. QUERY sorts by column C internally but only returns columns B and F.

Using column names instead of letters

QUERY uses column letters from the data range, not header names. ORDER BY Revenue causes an error. Use ORDER BY F instead.

Forgetting the comma between multiple sort columns

ORDER BY C F causes an error. Multiple columns need commas: ORDER BY C, F.

Tips

1. Combine ORDER BY with LIMIT for top-N reports. ORDER BY F DESC LIMIT 5 returns the 5 highest-revenue transactions. This is one of the most common QUERY patterns.

2. Sort aggregated columns in GROUP BY. You can ORDER BY an aggregate like SUM(F) or COUNT(F) after GROUP BY. The aggregate expression in ORDER BY must match the one in SELECT exactly.

3. Use ORDER BY with WHERE to build filtered, sorted reports in a single formula. No helper columns or manual sorting needed.

Tip

ORDER BY runs after WHERE and GROUP BY. If your WHERE clause eliminates rows you expected to see in the sorted result, check your filter conditions first.

Frequently Asked Questions

How do you sort QUERY results in Google Sheets?

Add ORDER BY to your query string. For example, =QUERY(A1:G11, "SELECT * ORDER BY F DESC") sorts all rows by the Revenue column from highest to lowest. Use ASC for ascending or DESC for descending.

Can you sort by multiple columns in QUERY?

Yes. List the columns separated by commas: ORDER BY C ASC, F DESC. This sorts by Region alphabetically first, then by Revenue descending within each region.

What is the default sort order in QUERY ORDER BY?

The default is ascending (ASC). If you write ORDER BY F without specifying ASC or DESC, QUERY sorts from smallest to largest for numbers and A to Z for text.

Can you combine ORDER BY with WHERE and GROUP BY?

Yes. Clauses go in this order: SELECT, WHERE, GROUP BY, ORDER BY, LIMIT. For example: SELECT C, SUM(F) WHERE F > 200 GROUP BY C ORDER BY SUM(F) DESC.

Does QUERY ORDER BY sort dates correctly?

Yes. QUERY recognizes date columns and sorts them chronologically. ORDER BY A ASC sorts from earliest to latest date. ORDER BY A DESC sorts from most recent to oldest.

Frequently Asked Questions

Next Steps

Continue learning with these related tutorials: