To remove duplicate rows from the result of an SQL SELECT statement, which qualifier must be included in the query?

Difficulty: Easy

Correct Answer: DISTINCT

Explanation:


Introduction / Context:
When you run an SQL SELECT statement, the default behaviour is to return all matching rows, including duplicates. In many reporting and analytic scenarios, you may want each combination of selected columns to appear only once, even if multiple underlying rows share the same values. SQL provides a simple qualifier to achieve this behaviour. This question asks which qualifier must be specified in the SELECT clause to remove duplicate rows from the result set.


Given Data / Assumptions:

    We are working with standard SQL SELECT statements.
    The SELECT clause can optionally include a qualifier that affects how duplicate rows are handled.
    The database by default returns all matching rows unless instructed otherwise.
    The goal is to get a distinct set of rows based on the columns listed in the SELECT clause.
    We are not using GROUP BY solely to remove duplicates, although that can sometimes have a similar effect.


Concept / Approach:
The DISTINCT keyword in SQL is used immediately after SELECT to indicate that duplicate rows should be removed from the result set. For example, SELECT DISTINCT city FROM customers returns each city value only once, even if many customers live in the same city. Some database products also accept UNIQUE as a synonym in certain contexts, but DISTINCT is the widely recognized standard keyword for this purpose. The other words listed in the options are not standard SQL qualifiers for removing duplicates.


Step-by-Step Solution:
Step 1: Recall the basic syntax. SELECT DISTINCT column_list FROM table_name removes duplicates for the combination of columns in column_list. Step 2: Recognize that no qualifier at all, or qualifiers such as ONLY or SINGLE, are not part of standard SQL for this purpose. Step 3: Remember that while some implementations may support UNIQUE in certain contexts, the standard and most commonly used keyword for duplicate elimination is DISTINCT. Step 4: Choose DISTINCT as the correct qualifier.


Verification / Alternative check:
You can easily verify this by writing a test query. If you have a table with duplicate values in a column, run SELECT column_name FROM table_name and observe that duplicates appear. Then run SELECT DISTINCT column_name FROM table_name and observe that each value appears only once. This clear behavioural difference confirms that DISTINCT is the keyword that removes duplicate rows from the result set.


Why Other Options Are Wrong:
ONLY is not a standard SQL qualifier for duplicate removal. It might appear in some vendor specific extensions but does not serve this purpose in general.
UNIQUE is sometimes used in data definition statements, such as creating unique constraints or indexes, but it is not the usual qualifier in SELECT statements for removing duplicate rows.
SINGLE is not a standard SQL keyword related to row uniqueness in query results.


Common Pitfalls:
A common pitfall is to use DISTINCT inappropriately, such as placing it on queries where duplicates were not actually a problem, which can lead to unnecessary sorting and performance overhead. Another mistake is to think that DISTINCT applies to each column separately; in fact, it applies to the entire row as defined by the selected columns. Understanding this behaviour helps avoid confusion when multiple columns are selected.


Final Answer:
To remove duplicate rows from a SELECT result, you must include the DISTINCT qualifier.

More Questions from Database

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion