On January 21th at 14:15 UTC , progression through exercises will be unavailable for 10 minutes due to a planned maintenance break.
Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
4. ORDER BY with conditions
Limiting the output
Eliminating duplicate results
HAVING: filtering and ordering groups
Let's practice


Excellent! Now, you can easily find the employees with the lowest and highest salaries. Pretty easy, right?

We can filter rows and sort them at the same time. Have a look:

FROM Order
WHERE CustomerId = 100
ORDER BY TotalSum;

The WHERE and ORDER BY clauses work well together. In this case, we'll only see the orders made by the customer with ID 100. The orders will be sorted by the total sum – the cheapest order will appear first, and the most expensive order will appear last.


Select only the rows related to the year 2011 from the Employee table. Sort them by salary.

Stuck? Here's a hint!


FROM Employee
WHERE Year = 2011
ORDER BY Salary;