Concept Flow - ORDER BY single column
Start Query
Fetch Rows from Table
Sort Rows by Column
Return Sorted Rows
End Query
The query fetches all rows, sorts them by one column, then returns the sorted list.
SELECT name, age FROM users ORDER BY age;
| Step | Action | Data State | Result |
|---|---|---|---|
| 1 | Fetch all rows from users | [{name: 'Alice', age: 30}, {name: 'Bob', age: 25}, {name: 'Carol', age: 35}] | All rows fetched unsorted |
| 2 | Sort rows by age ascending | [{name: 'Bob', age: 25}, {name: 'Alice', age: 30}, {name: 'Carol', age: 35}] | Rows sorted by age |
| 3 | Return sorted rows | [{name: 'Bob', age: 25}, {name: 'Alice', age: 30}, {name: 'Carol', age: 35}] | Query result returned |
| 4 | End query | N/A | Execution complete |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| rows | empty | [{name: 'Alice', age: 30}, {name: 'Bob', age: 25}, {name: 'Carol', age: 35}] | [{name: 'Bob', age: 25}, {name: 'Alice', age: 30}, {name: 'Carol', age: 35}] | [{name: 'Bob', age: 25}, {name: 'Alice', age: 30}, {name: 'Carol', age: 35}] |
ORDER BY single column: - Syntax: SELECT columns FROM table ORDER BY column_name; - Sorts rows by one column in ascending order by default. - Use DESC for descending order. - Returns all rows sorted by that column. - Sorting happens after fetching rows.