Difficulty: Easy
Correct Answer: Incorrect
Explanation:
Introduction / Context:
Sorting is fundamental in reporting and pagination. This question evaluates whether ORDER BY can handle multiple sort keys (e.g., last_name, first_name) or if it is limited to a single column.
Given Data / Assumptions:
Concept / Approach:
SQL ORDER BY supports a comma-separated list of expressions, each with its own direction. For instance, ... ORDER BY last_name ASC, first_name ASC; sorts primarily by last_name and uses first_name to break ties. This generalizes to any number of keys, including expressions (e.g., ORDER BY COALESCE(priority, 999), created_at DESC).
Step-by-Step Solution:
Verification / Alternative check:
Run an example and compare: ORDER BY department, salary DESC clearly sorts first by department, then within each department by salary descending.
Why Other Options Are Wrong:
Common Pitfalls:
Relying on implicit sort order or assuming rows are returned in insertion order. Always specify ORDER BY explicitly for deterministic presentation.
Final Answer:
Incorrect
Discussion & Comments