Recall & Review
beginner
What does the
ORDER BY clause do in a SQL query?It sorts the rows returned by the query based on one or more columns, either in ascending or descending order.
Click to reveal answer
beginner
How do you sort query results by a single column in ascending order?
Use
ORDER BY column_name ASC. ASC means ascending order and is the default if not specified.Click to reveal answer
beginner
How do you sort query results by a single column in descending order?
Use
ORDER BY column_name DESC. DESC means descending order.Click to reveal answer
beginner
What happens if you use
ORDER BY without specifying ASC or DESC?The results are sorted in ascending order by default.
Click to reveal answer
beginner
Write a simple SQL query to select all columns from a table named
employees and order the results by the last_name column.SELECT * FROM employees ORDER BY last_name;
Click to reveal answer
What does
ORDER BY salary DESC do?✗ Incorrect
DESC means descending order, so salaries are sorted from highest to lowest.
Which keyword sorts data in ascending order?
✗ Incorrect
ASC sorts data in ascending order. It is also the default if no keyword is specified.
What is the default sort order if you write
ORDER BY age without ASC or DESC?✗ Incorrect
By default, ORDER BY sorts in ascending order.
Which SQL clause is used to sort query results?
✗ Incorrect
ORDER BY sorts the results of a query.
How would you sort a table named
products by the price column in ascending order?✗ Incorrect
Use ORDER BY price ASC to sort prices from lowest to highest.
Explain how to use the
ORDER BY clause to sort data by a single column in SQL.Think about how you tell SQL to arrange rows by one column.
You got /4 concepts.
Write an example SQL query that selects all data from a table and sorts it by a column named
date_created in descending order.Use ORDER BY with DESC to sort newest first.
You got /3 concepts.