Summary

This chapter focuses on sorting. It covers the following topics:

  • Sorting query results with ORDER BY. You can sort up or down, and you can sort by column, display label, or position in the SELECT list. Sorts can be nested.

  • Eliminating duplicate result rows with DISTINCT. DISTINCT can be a little tricky because it must be the first element in the SELECT list, and it applies to all elements. DISTINCT looks for all unique combinations of the listed expressions.

  • Finding summary values with aggregates (SUM, MIN, MAX, AVG, and COUNT). Just to keep you on your toes, the rules for DISTINCT with aggregates are different from the rules for DISTINCT with expressions.

The next chapter explores the GROUP BY clause and the use of aggregate functions ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.