Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
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 of them can be sorted in a different order:

SELECT *
FROM order
ORDER BY customer_id ASC, total_sum DESC;

As you can see, the results will first be sorted by customer_id in the ascending order (lowest values first) and then, for each customer_id, the orders will be sorted by the total_sum in the descending order (greatest values first).

Exercise

Select all rows from the employees table and sort them in the ascending order by the department and then in the descending order by the salary.

Stuck? Here's a hint!

Type:

SELECT *
FROM employees
ORDER BY
  department ASC,
  salary DESC;