Difficulty: Easy
Correct Answer: SELECT DISTINCT SUB FROM BOOK
Explanation:
Introduction / Context:
SQL provides the DISTINCT keyword to remove duplicate rows from a projection. When you need a list of unique values from a column, DISTINCT is the standard, portable approach across vendors.
Given Data / Assumptions:
Concept / Approach:
SELECT DISTINCT column_list returns each unique combination of the listed columns exactly once. SELECT column without DISTINCT returns all rows (including duplicates). SELECT ALL is the default behavior (it does not de-duplicate). Therefore, to obtain unique subject values, we must use DISTINCT with the specific column.
Step-by-Step Solution:
Identify the target: unique values of SUB.Choose the SQL construct for uniqueness: DISTINCT.Write the minimal projection: SELECT DISTINCT SUB FROM BOOK.
Verification / Alternative check:
Running SELECT SUB FROM BOOK ORDER BY SUB would still show duplicates; wrapping with DISTINCT removes them. Some systems also support GROUP BY SUB to get unique SUB values, but DISTINCT is simpler and clearer.
Why Other Options Are Wrong:
Common Pitfalls:
Using DISTINCT with multiple columns inadvertently groups by the entire combination; ensure only necessary columns are projected when deduplication is intended.
Final Answer:
SELECT DISTINCT SUB FROM BOOK
Discussion & Comments