One problem with this article is the number of times the solution involves COUNT(DISTINCT).
One of the best SQL interview questions is "Explain what is wrong with DISTINCT and how to work around it".
One of the best SQL interview questions is "Explain what is wrong with DISTINCT and how to work around it".
https://sqlperformance.com/2017/01/t-sql-queries/surprises-a...
But every time, it interferes badly with any kind of locking (that's DBMS dependent, of course), and imposes a high performance penalty (on every DBMS).
Often better to group explicitly so you know what's actually going on.
Bingo. I used to work with a guy who would see duplicate results and just throw a distinct on his query. I had to keep on him to fix his queries or explain why distinct was correct in this case. My default is that distinct is almost always not the solution.