How SQL's DISTINCT clause works?
DISTINCT filters out duplicate values of your returned fields.
A really simplified way to look at it is:
- It builds your overall result set (including duplicates) based on your
- It sorts that result set based on the fields you want to return
- It removes any duplicate values in those fields
It's semantically equivalent to a
GROUP BY where all returned fields are in the
GROUP BY clause.