logoalt Hacker News

petalmindlast Tuesday at 5:32 PM2 repliesview on HN

Frankly I don't think that overcounting is solved by normalizing, because it's easy to write an overcounting SQL query over perfectly normalized data.

I tried to explain the real cause of overcounting in my "Modern Guide to SQL JOINs":

https://kb.databasedesignbook.com/posts/sql-joins/#understan...


Replies

mickeyplast Wednesday at 11:02 AM

I'll go one further and say that if you're reaching for DISTINCT and you have joins, you may have joined the data the wrong way. It's not a RULE, but it's ALWAYS a 'smell' when I see a query that uses DISTINCT to shove away duplicate matches. I always add a comment for the exceptions.

estetlinuslast Wednesday at 7:32 AM

Great read, thank you!