What is the purpose of the ORDER BY clause in MySQL?
A
To filter results B
To group results C
To sort the results D
To count the results
Analysis & Theory
The ORDER BY clause is used to sort the result set in ascending or descending order.
What is the default sort order used by ORDER BY in MySQL?
A
Descending B
Random C
Grouped D
Ascending
Analysis & Theory
By default, ORDER BY sorts the result in ascending (ASC) order.
How do you sort the result set in descending order using ORDER BY?
A
ORDER BY column DOWN B
ORDER BY column DESC C
SORT column DESC D
ORDER column BY DESC
Analysis & Theory
To sort in descending order, use ORDER BY column_name DESC.
Which keyword is used to sort the result in ascending order?
A
ASC B
UP C
INCREASE D
FIRST
Analysis & Theory
ASC is used to explicitly sort in ascending order.
What will this query do? `SELECT * FROM users ORDER BY age DESC;`
A
Sorts users by age in ascending order B
Sorts users by name C
Sorts users by age in descending order D
Filters users with age above a limit
Analysis & Theory
The query sorts the result by the `age` column in descending order.
Can you sort results by multiple columns using ORDER BY?
A
No B
Only in SELECT * C
Yes, using commas between column names D
Yes, using semicolons between column names
Analysis & Theory
You can sort by multiple columns using commas: ORDER BY col1, col2.
What will `ORDER BY name, age DESC` do?
A
Sort only by name B
Sort by name ascending, then by age descending C
Sort both name and age in descending order D
Sort name descending, then age ascending
Analysis & Theory
It sorts first by `name` ascending, then `age` in descending order for rows with the same name.
Which part of the query is executed last in SELECT statements?
A
SELECT B
FROM C
WHERE D
ORDER BY
Analysis & Theory
ORDER BY is the last clause executed in the SELECT query lifecycle.
Which query correctly sorts products by price and then by name?
A
SELECT * FROM products ORDER price, name; B
SELECT * FROM products SORT BY price, name; C
SELECT * FROM products ORDER BY price, name; D
SELECT * FROM products BY price THEN name;
Analysis & Theory
The correct syntax is: ORDER BY price, name;
Which ORDER BY clause will sort names in descending alphabetical order?
A
ORDER BY name DOWN; B
ORDER BY name ASC; C
ORDER BY name Z-A; D
ORDER BY name DESC;
Analysis & Theory
ORDER BY name DESC sorts names in descending (Z to A) order.