Difficulty: Easy
Correct Answer: Incorrect
Explanation:
Introduction / Context: SELECT DISTINCT is commonly used to eliminate duplicate rows in result sets. Misunderstanding this leads to the opposite of the desired output. This question checks whether you know the exact role of DISTINCT.
Given Data / Assumptions:
Concept / Approach: SELECT DISTINCT applies a set operation over the projected columns, removing duplicate rows and returning only unique combinations. If the goal is to see duplicates, one would use GROUP BY with HAVING COUNT() > 1 or window functions (for example, COUNT() OVER(PARTITION BY ...)) to identify duplicates, not DISTINCT. Therefore, the statement claiming DISTINCT shows duplicates is the opposite of reality.
Step-by-Step Solution:
To remove duplicates: SELECT DISTINCT col1, col2 FROM T.To find duplicates: SELECT col1, COUNT() FROM T GROUP BY col1 HAVING COUNT() > 1.To mark duplicates without filtering: SELECT col1, COUNT(*) OVER(PARTITION BY col1) AS dup_cnt FROM T.Conclusion: DISTINCT removes, not reveals, duplicates.Verification / Alternative check: Run sample data with repeated values; DISTINCT returns unique rows, while GROUP BY/HAVING reveals duplicates.
Why Other Options Are Wrong:
Common Pitfalls: Using DISTINCT to “fix” unintended duplicates created by joins instead of correcting the join logic; assuming DISTINCT is per-column.
Final Answer: Incorrect
Discussion & Comments