The query sorts rows by price in ascending order (lowest to highest).
Step 2: Sort the data by price
Prices sorted ascending: 20 (id 2), 30 (id 3), 50 (id 1). So the id order is [2, 3, 1].
Final Answer:
[2, 3, 1] -> Option B
Quick Check:
Sort by price ASC = [2, 3, 1] [OK]
Hint: Sort by column values ascending to find order [OK]
Common Mistakes:
Confusing ASC with DESC order
Sorting by id instead of price
Ignoring the ORDER BY clause
4. Identify the error in this query:
SELECT name FROM customers ORDER salary DESC;
medium
A. ORDER BY must come before SELECT
B. DESC cannot be used with ORDER
C. Missing BY keyword after ORDER
D. Missing WHERE clause
Solution
Step 1: Check ORDER BY syntax
The correct syntax requires the keyword BY after ORDER. The query uses ORDER salary DESC which is invalid.
Step 2: Confirm other parts are correct
DESC is valid with ORDER BY. No WHERE clause is needed for sorting. ORDER BY comes after SELECT.
Final Answer:
Missing BY keyword after ORDER -> Option C
Quick Check:
ORDER BY needs BY keyword [OK]
Hint: Always write ORDER BY, not just ORDER [OK]
Common Mistakes:
Omitting BY after ORDER
Using ORDER before SELECT
Confusing DESC usage
5. You have a table students with columns name and score. You want to list all students sorted by their score from highest to lowest, but if two students have the same score, sort those students alphabetically by name ascending. Which query achieves this?
hard
A. SELECT * FROM students ORDER BY score DESC, name ASC;
B. SELECT * FROM students ORDER BY name ASC, score DESC;
C. SELECT * FROM students ORDER BY score ASC, name DESC;
D. SELECT * FROM students ORDER BY score DESC;
Solution
Step 1: Understand sorting requirements
Primary sort is by score descending (highest first). Secondary sort for ties is by name ascending (alphabetical).
Step 2: Match query with requirements
SELECT * FROM students ORDER BY score DESC, name ASC; orders by score DESC then name ASC, matching the requirement. SELECT * FROM students ORDER BY name ASC, score DESC; reverses order priorities. SELECT * FROM students ORDER BY score ASC, name DESC; sorts score ascending and name descending, which is wrong. SELECT * FROM students ORDER BY score DESC; misses secondary sort.
Final Answer:
SELECT * FROM students ORDER BY score DESC, name ASC; -> Option A
Quick Check:
ORDER BY score DESC, name ASC = correct [OK]
Hint: Use multiple columns in ORDER BY for tie-breakers [OK]
Common Mistakes:
Reversing sort order priorities
Missing secondary sort column
Using ASC when DESC needed
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.