Junior — Middle
What is the function of the DISTINCT operator in SQL and how does it affect the query results?
sobes.tech AI
Answer from AI
The DISTINCT operator in SQL is used to select unique values from a column or set of columns. It removes duplicates from the query result, returning only unique rows.
For example, if a table has multiple records with the same value in the city column, the query:
SELECT DISTINCT city FROM users;
will return a list of unique cities without repetitions.
Thus, DISTINCT affects the query results by reducing the number of rows through the exclusion of duplicate values.