07-20-2023, 02:48 PM
I've placed this answer because Erwin Smout posted a [answer](
Erwin suggested:
>"Why should every SELECT always include DISTINCT ?"
A more appropriate question would be: If someone were to make the claim that: "every SELECT always include DISTINCT"; how would you comment on the claim?
If a candidate is unable to shoot the claim down in flames they either:
* Don't understand the problem with the claim.
* Lack in critical thinking skills.
* Lack in ability to communicate technical issues.
**For the record**
1. ***Suppose your query is correct***, and does not return any duplicates, then including DISTINCT simply forces the RDBMS to check your result (zero benefit, and a lot of additional processing).
2. ***Suppose your query is incorrect***, and _does_ return duplicates, then including DISTINCT simply **hides** the problem (again with additional processing). It would be better to spot the problem and fix your query... it'll run faster that way.
[To see links please register here]
) that was so wrong it highlighted that there is probably a need to specifically guard against it.Erwin suggested:
>"Why should every SELECT always include DISTINCT ?"
A more appropriate question would be: If someone were to make the claim that: "every SELECT always include DISTINCT"; how would you comment on the claim?
If a candidate is unable to shoot the claim down in flames they either:
* Don't understand the problem with the claim.
* Lack in critical thinking skills.
* Lack in ability to communicate technical issues.
**For the record**
1. ***Suppose your query is correct***, and does not return any duplicates, then including DISTINCT simply forces the RDBMS to check your result (zero benefit, and a lot of additional processing).
2. ***Suppose your query is incorrect***, and _does_ return duplicates, then including DISTINCT simply **hides** the problem (again with additional processing). It would be better to spot the problem and fix your query... it'll run faster that way.