Difficulty: Easy
Correct Answer: ORDER BY.
Explanation:
Introduction / Context:
Sorting query results is a routine task in SQL. Whether you are listing customers by last name or transactions by amount, you need the correct clause to impose a predictable order on the rows returned by a SELECT statement. Knowing which keyword performs sorting prevents inefficient workarounds and ensures portable SQL.
Given Data / Assumptions:
Concept / Approach:
The SQL clause that specifies the order of rows in a result set is ORDER BY. It accepts one or more sort expressions, optional ASC or DESC modifiers, and can include positional ordinals or expressions. GROUP BY is for aggregating rows, not sorting. There is no standard SORT BY or ARRANGE BY in SQL.
Step-by-Step Solution:
Verification / Alternative check:
Add ORDER BY to a sample query such as: SELECT last_name FROM customers ORDER BY last_name ASC; The database returns names alphabetically, confirming usage.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming GROUP BY sorts rows. Some engines may produce seemingly sorted output after GROUP BY, but this is not guaranteed by the SQL standard. Always use ORDER BY for deterministic ordering.
Final Answer:
ORDER BY.
Discussion & Comments