Ordering
6. Sort by a few columns
Limiting the output
Eliminating duplicate results
Aggregation
Grouping
HAVING: filtering and ordering groups
Let's practice

Instruction

Good job! All right, one more thing before we move on: you can sort your results by more than one column, and each column can be sorted in a different order:

SELECT
  *
FROM Order
ORDER BY CustomerId ASC,
  TotalSum DESC;

As you can see, the results will first be sorted by CustomerId in ascending order (lowest values first). Then, for each CustomerId, the orders will be sorted by TotalSum in descending order (greatest values first).

Exercise

Select all rows from the Employee talbe, and sort them in ascending order by department and then in descending order by salary.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM Employee
ORDER BY Department ASC,
  Salary DESC;