What does the ORDER BY clause do in SQL?
A
Filters rows based on conditions B
Groups rows by column values C
Sorts the query results D
Limits the number of rows returned
Analysis & Theory
ORDER BY sorts the result set in ascending or descending order.
Which keyword is used to sort results in descending order?
A
DOWN B
DESC C
REVERSE D
DECREASE
Analysis & Theory
Use DESC to sort results in descending order.
How are rows sorted by default when ORDER BY is used without specifying ASC or DESC?
A
Descending B
Randomly C
Ascending D
By primary key
Analysis & Theory
The default sort order is ascending.
Which query sorts employees by salary from highest to lowest?
A
SELECT * FROM employees ORDER BY salary DESC; B
SELECT * FROM employees ORDER salary DESC; C
SELECT * FROM employees SORT BY salary DESC; D
SELECT * FROM employees ORDER BY salary DOWN;
Analysis & Theory
ORDER BY column DESC sorts in descending order.
How do you sort rows by 'last_name' ascending and then by 'first_name' ascending?
A
ORDER BY last_name, first_name B
ORDER BY last_name ASCENDING, first_name ASCENDING C
ORDER BY last_name THEN first_name D
ORDER last_name, first_name
Analysis & Theory
Multiple columns are listed separated by commas, defaulting to ASC.
Which clause can you combine with ORDER BY to return only a limited number of rows?
A
GROUP BY B
LIMIT C
HAVING D
DISTINCT
Analysis & Theory
LIMIT restricts the number of rows returned.
What does this query do?
SELECT * FROM products ORDER BY price ASC;
A
Selects products with the highest price B
Sorts products by price in ascending order C
Sorts products by price in descending order D
Filters products where price is positive
Analysis & Theory
ASC explicitly specifies ascending order.
How do you sort rows by 'created_at' date newest first?
A
ORDER BY created_at ASC B
ORDER BY created_at DESC C
ORDER BY created_at NEWEST D
ORDER created_at DESC
Analysis & Theory
DESC sorts dates from newest to oldest.
Which of these statements is TRUE about ORDER BY?
A
ORDER BY can only sort numeric columns B
ORDER BY must come before WHERE C
ORDER BY can sort by multiple columns D
ORDER BY removes duplicate rows
Analysis & Theory
ORDER BY supports sorting by multiple columns.
How do you sort by 'category' ascending and 'price' descending?
A
ORDER BY category ASC, price DESC B
ORDER BY category, price DOWN C
ORDER category ASCENDING, price DESCENDING D
ORDER BY category UP, price DOWN
Analysis & Theory
Specify ASC and DESC for each column explicitly.