Recall & Review
beginner
What does the
ORDER BY clause do in SQL?It sorts the rows returned by a query based on one or more columns.
Click to reveal answer
beginner
What is the default sorting order when using
ORDER BY without specifying ASC or DESC?The default sorting order is ascending (
ASC).Click to reveal answer
beginner
How do you sort query results in descending order?
Use
ORDER BY column_name DESC to sort results from highest to lowest or Z to A.Click to reveal answer
intermediate
Can you sort by multiple columns using
ORDER BY? How?Yes. List columns separated by commas, e.g.,
ORDER BY column1 ASC, column2 DESC.Click to reveal answer
intermediate
What happens if you mix
ASC and DESC in the same ORDER BY clause?Each column sorts independently in the specified order, e.g., first ascending, then descending.
Click to reveal answer
What does
ORDER BY name DESC do?✗ Incorrect
DESC means descending order, so names are sorted from Z to A.
Which is the correct way to sort by age ascending and then by name descending?
✗ Incorrect
Use ORDER BY age ASC, name DESC to sort age low to high, then name Z to A.
If you write
ORDER BY salary without ASC or DESC, what happens?✗ Incorrect
Default sorting order is ascending if not specified.
Can
ORDER BY sort by columns not in the SELECT list?✗ Incorrect
Some SQL versions allow it, others require the column in SELECT.
What is the effect of
ORDER BY date DESC, price ASC?✗ Incorrect
First sorts dates newest to oldest, then prices low to high within same date.
Explain how to use
ORDER BY to sort query results by multiple columns with different orders.Think about sorting a list first by one rule, then by another.
You got /4 concepts.
Describe what happens if you omit
ASC or DESC in an ORDER BY clause.What is the usual way to sort numbers or letters?
You got /3 concepts.