0
0
Google Sheetsspreadsheet~5 mins

ORDER BY clause in Google Sheets - Step-by-Step Guide

Choose your learning style9 modes available
Introduction
The ORDER BY clause in Google Sheets helps you sort data in a specific order. It is used inside the QUERY function to arrange rows by one or more columns, either from smallest to largest or largest to smallest. This makes it easier to find top values or organize your data clearly.
When you want to list sales data from highest to lowest to see the best sellers.
When you need to sort a list of names alphabetically for a contact sheet.
When you want to organize dates from earliest to latest in an event schedule.
When you want to display students' scores sorted from highest to lowest.
When you want to sort product prices from lowest to highest to find bargains.
Steps
Step 1: Click
- a blank cell where you want the sorted data to appear
The cell is selected and ready for formula input
Step 2: Type
- the formula bar
You start entering the QUERY formula
💡 Start with =QUERY(data_range, "SELECT * ORDER BY column_number")
Step 3: Replace
- data_range in the formula
The formula points to your actual data range, for example A1:C10
Step 4: Replace
- column_number in the ORDER BY clause
The formula sorts by the chosen column number, for example 2 for the second column
Step 5: Add
- after the column number in ORDER BY clause
You specify sorting order by adding ASC for ascending or DESC for descending
💡 Example: ORDER BY 2 DESC sorts column 2 from largest to smallest
Step 6: Press
- Enter key
The sorted data appears in the selected cell range
Before vs After
Before
Data in A1:C5 with names and scores unsorted
After
Data sorted by scores in descending order showing highest scores first
Settings Reference
data_range
📍 inside QUERY formula
Defines the data to be sorted
Default: None
ORDER BY clause
📍 inside QUERY formula's query string
Sets which column to sort by and the sort direction
Default: ASC
SELECT clause
📍 inside QUERY formula's query string
Defines which columns to show in the result
Default: *
Common Mistakes
Using column letters instead of numbers in ORDER BY clause
QUERY requires column numbers, not letters, inside ORDER BY
Use the column number like ORDER BY 2 instead of ORDER BY B
Forgetting to put the query string inside double quotes
QUERY formula needs the query text as a string to work
Always enclose the query part in double quotes, e.g., "SELECT * ORDER BY 1"
Not specifying ASC or DESC when needed
Without ASC or DESC, the default is ascending, which may not be what you want
Add ASC for ascending or DESC for descending explicitly to avoid confusion
Summary
ORDER BY clause sorts data inside the QUERY function by one or more columns.
Use column numbers, not letters, to specify which column to sort.
Add ASC or DESC to control ascending or descending order.