What does the DISTINCT keyword do in an SQL query?
a) It removes duplicate rows from the result set
b) It selects only the first row of the result set
c) It selects only rows with null values
d) It combines rows with similar values
Answer:
a) It removes duplicate rows from the result set
Explanation:
The DISTINCT keyword in SQL is used to remove duplicate rows from the result set, ensuring that only unique rows are returned. It is commonly used when a query retrieves multiple records with identical values and only distinct results are needed.
For example, SELECT DISTINCT city FROM customers will return a list of unique cities from the customers table, excluding duplicates.
Using DISTINCT can help clean up query results and provide a more accurate summary of data.