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 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:

SELECT
 *
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.

Exercise

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

Stuck? Here's a hint!

Type:

SELECT
 *
FROM Employee
WHERE Year = 2011
ORDER BY Salary;