DataBolt

SQL LEARNING PLATFORM

6

CHAPTER 6

ORDER, BY

Controlling the sequence of your results.

4

Learning Blocks

SQL

Interactive Queries

In This Chapter

Concepts you'll master

1

Ascending (ASC) and descending (DESC) sort

2

Sorting by multiple columns — primary and secondary sort

3

Sorting by expressions and aliases

8.1 - Ascending and Descending

SQL QUERY
SELECT name, salary 
FROM employees
ORDER BY salary ASC;

8.2 - Multi-Column Sort

SQL QUERY
SELECT name, department, salary
FROM employees
ORDER BY department ASC, salary DESC;

🌟 Note: SQL reads ORDER BY columns left to right: first sort by department (A→Z), then within each department sort by salary (high→low).

Exercise

Practice your SQL skills

SQL EDITOR
Press semicolon (;) to auto-run query

Tasks

Complete all SQL challenges

1

Sort employees by salary in ascending order.

Current Task
2

Sort employees by salary in descending order.

3

Sort employees by department in alphabetical order.

4

Sort employees by department (A-Z) and within each department by salary (highest first).

Need help solving this task?