Section 1 - Instruction

Last time you learned to filter rows with WHERE. But did you know that your filtered results appear in unpredictable order? One query might show books alphabetically, another might be completely random.

Without controlling the order, finding specific results becomes frustrating.

Engagement Message

Which single criterion would you use to sort your search results?

Section 2 - Instruction

The ORDER BY clause solves this by sorting your results in a predictable sequence. It's like organizing books on a shelf - by title, price, or any other criteria you choose.

ORDER BY transforms chaotic results into organized, scannable lists.

Engagement Message

Which would be easier to read: random book prices or prices sorted from lowest to highest?

Section 3 - Instruction

Here's the basic ORDER BY structure:

Notice ORDER BY comes after WHERE. It sorts the filtered results by the specified column.

Engagement Message

Can you predict the order the books will appear in after running this query?

Section 4 - Instruction

By default, ORDER BY sorts in ascending order (smallest to largest, A to Z). Add DESC for descending order (largest to smallest, Z to A):

This shows the most expensive books first.

Engagement Message

When might descending order be more useful than ascending?

Section 5 - Instruction

You can be explicit about ascending order using ASC:

ASC and DESC make your intentions crystal clear, even though ASC is the default.

Engagement Message

Which is clearer: or ?

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal