0
0
Google Sheetsspreadsheet~10 mins

ORDER BY clause in Google Sheets - Cell-by-Cell Formula Trace

Choose your learning style9 modes available
Sample Data

This table shows names of students and their scores.

CellValue
A1Name
B1Score
A2Alice
B285
A3Bob
B392
A4Charlie
B478
A5Diana
B590
Formula Trace
=QUERY(A1:B5, "SELECT A, B ORDER BY B DESC", 1)
Step 1: QUERY(A1:B5, "SELECT A, B ORDER BY B DESC", 1)
Step 2: Data rows before sorting: [Alice 85, Bob 92, Charlie 78, Diana 90]
Step 3: Sort rows by Score descending: [Bob 92, Diana 90, Alice 85, Charlie 78]
Step 4: Add header row: [Name, Score]
Step 5: Final output: [Name Score; Bob 92; Diana 90; Alice 85; Charlie 78]
Cell Reference Map
    A       B
1 |Name   |Score |
2 |Alice  |  85  |
3 |Bob    |  92  |
4 |Charlie|  78  |
5 |Diana  |  90  |

Formula references range A1:B5 for data and headers.
The formula uses the data and headers in cells A1 to B5.
Result
    D       E
1 |Name   |Score |
2 |Bob    |  92  |
3 |Diana  |  90  |
4 |Alice  |  85  |
5 |Charlie|  78  |
The QUERY formula outputs the table sorted by Score descending, showing the highest scores first.
Sheet Trace Quiz - 3 Questions
Test your understanding
What does the ORDER BY B DESC part do in the formula?
AFilters rows where column B is greater than DESC
BSorts the rows by column B from highest to lowest
CSorts the rows by column A alphabetically
DSelects only column B
Key Result
QUERY(range, "SELECT columns ORDER BY column DESC", headers) sorts data by a column descending.