DISTINCT Operator
The DISTINCT
operator is used to return only unique values, eliminating duplicates from the query results.
Example: Using DISTINCT
SELECT DISTINCT City
FROM FreedomFighters;
Output:
Returns a list of unique cities where freedom fighters are from.
Do's and Don'ts
Do's
- Use
DISTINCT
to remove duplicates from result sets. - Combine with multiple columns to get unique combinations.
Don'ts
- Don't use
DISTINCT
unnecessarily, as it can impact performance. - Don't assume
DISTINCT
will always speed up your query.