Recall & Review
beginner
What does the SQL clause
ORDER BY do?The
ORDER BY clause sorts the rows returned by a query based on one or more columns, either in ascending (default) or descending order.Click to reveal answer
beginner
How do you sort query results by multiple columns in SQL?
You list the columns separated by commas in the
ORDER BY clause. For example: ORDER BY column1 ASC, column2 DESC sorts first by column1 ascending, then by column2 descending if there are ties.Click to reveal answer
intermediate
Why would you use multiple columns in an
ORDER BY clause?Using multiple columns helps organize data more precisely. For example, sorting a list of people by last name and then by first name ensures all last names are grouped and within each group, first names are sorted.
Click to reveal answer
beginner
What is the default sort order in SQL when using
ORDER BY?The default sort order is ascending (smallest to largest or A to Z) if you do not specify
ASC or DESC.Click to reveal answer
beginner
Write a simple SQL query to select all columns from a table named
Employees and sort by Department ascending and Salary descending.SELECT * FROM Employees ORDER BY Department ASC, Salary DESC;
Click to reveal answer
What happens if you use
ORDER BY column1, column2 in a SQL query?✗ Incorrect
The
ORDER BY clause sorts rows first by the first column listed, then by the second column if there are ties in the first.What is the default sorting order when you use
ORDER BY column without specifying ASC or DESC?✗ Incorrect
SQL sorts in ascending order by default if no order is specified.
Which SQL clause is used to sort query results by multiple columns?
✗ Incorrect
The
ORDER BY clause sorts results by one or more columns.How do you sort by
Age descending and then by Name ascending?✗ Incorrect
You specify each column with its sort order separated by commas.
If two rows have the same value in the first column of an ORDER BY clause, how are they sorted?
✗ Incorrect
Ties in the first column are resolved by sorting on the next column(s) listed.
Explain how the
ORDER BY clause works when sorting by multiple columns in SQL.Think about sorting a list of names by last name then first name.
You got /4 concepts.
Write an SQL query to select all data from a table called
Products and sort by Category ascending and Price descending.Remember to separate columns with commas in ORDER BY.
You got /2 concepts.