0
0
SQLquery~20 mins

ORDER BY single column in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ORDER BY Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this query ordering by age ascending?
Given the table People with columns id, name, and age, what will be the order of names after running this query?
SELECT name FROM People ORDER BY age ASC;
SQL
CREATE TABLE People (id INT, name VARCHAR(20), age INT);
INSERT INTO People VALUES (1, 'Alice', 30), (2, 'Bob', 25), (3, 'Charlie', 35);
ABob, Alice, Charlie
BAlice, Bob, Charlie
CCharlie, Alice, Bob
DBob, Charlie, Alice
Attempts:
2 left
💡 Hint
ORDER BY age ASC sorts from smallest to largest age.
query_result
intermediate
2:00remaining
What is the output order when ordering by salary descending?
Consider the table Employees with columns emp_id, emp_name, and salary. What is the order of emp_name after running this query?
SELECT emp_name FROM Employees ORDER BY salary DESC;
SQL
CREATE TABLE Employees (emp_id INT, emp_name VARCHAR(20), salary INT);
INSERT INTO Employees VALUES (1, 'John', 5000), (2, 'Jane', 7000), (3, 'Doe', 6000);
AJohn, Jane, Doe
BJohn, Doe, Jane
CDoe, Jane, John
DJane, Doe, John
Attempts:
2 left
💡 Hint
ORDER BY salary DESC sorts from highest to lowest salary.
📝 Syntax
advanced
2:00remaining
Which query will cause a syntax error?
Identify the query that will cause a syntax error when ordering by the column score.
ASELECT * FROM Results ORDER BY score;
BSELECT * FROM Results ORDER BY score DESC;
CSELECT * FROM Results ORDER BY score ASCENDING;
DSELECT * FROM Results ORDER BY score ASC;
Attempts:
2 left
💡 Hint
Check the valid keywords for sorting order in SQL.
optimization
advanced
2:00remaining
Which query is more efficient for ordering by a single indexed column?
Given a large table Sales with an index on the date column, which query will likely perform best when ordering by date?
ASELECT * FROM Sales ORDER BY date + 0;
BSELECT * FROM Sales ORDER BY date;
CSELECT * FROM Sales ORDER BY date DESC;
DSELECT * FROM Sales ORDER BY CAST(date AS VARCHAR);
Attempts:
2 left
💡 Hint
Using the indexed column directly helps the database use the index.
🧠 Conceptual
expert
2:00remaining
What happens if you ORDER BY a column with NULL values?
Consider a table Products with a column price that contains some NULL values. What is the default behavior of ORDER BY price ASC regarding NULLs?
ANULL values appear last in the result set.
BNULL values appear first in the result set.
CNULL values are excluded from the result set.
DThe query raises an error due to NULL values.
Attempts:
2 left
💡 Hint
Think about how SQL treats NULLs in sorting by default.