Back to AGGREGATIONS & GROUP BY, ORDER BY

ORDER BY

Understand ORDER BY clause for reordering result

2 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. IntroductionThe ORDER BY keyword is introduced as a powerful tool for sorting data results.
  2. Basic SortingA simple query demonstrates sorting the products table by the price column.
  3. Default OrderBy default, ORDER BY sorts data in ascending order (ASC).
  4. Descending OrderThe DESC keyword is used to sort results from highest to lowest values.
  5. Text SortingORDER BY works on text values, sorting them alphabetically.
  6. Multi-Column SortData can be sorted by a primary column and then a secondary column within those groups.
  7. Mixed DirectionsIt is possible to combine ASC and DESC within a single multi-column sort list.
  8. ConclusionThe lesson concludes by summarizing the flexibility of the ORDER BY clause for data organization.
PDF notes

Frequently asked questions

What is the default sort order if I don't specify ASC or DESC?

The default sort order is ascending (ASC), meaning lowest values or A-Z come first.

How do I sort by the highest prices first?

Use the DESC keyword immediately following the column name, such as ORDER BY price DESC.

Can I sort by both country and customer name?

Yes, list them separated by commas; the first column determines the primary sort.

Can I mix ascending and descending orders in one query?

Yes, specify ASC or DESC individually after each column name in the list.