Save up to $499! Grab all Python courses for $49 or all online courses we’ve ever launched for only $169. Only Feb 11-16. Happy Valentine's!
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;