Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
4. ORDER BY with conditions
Limiting the output
Eliminating duplicate results
Aggregation
Grouping
HAVING: filtering and ordering groups
Let's practice

Instruction

Excellent! Now you can easily examine who's got the lowest and the highest salary. It's not that hard, as you can see.

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

SELECT *
FROM orders
WHERE customer_id = 100
ORDER BY total_sum;

The WHERE clause and ORDER BY work well together.

In this case, we'll only see the orders made by the customer with id 100. The orders will be sorted on the total sum – the cheapest order will appear as the first result and the most expensive as the last one.

Exercise

Select only the rows related to 2011 from the employees table. Sort the result by the salary.

Stuck? Here's a hint!

Type:

SELECT *
FROM employees
WHERE year = 2011
ORDER BY salary;