Skip to content

Comment on SQL Design Patterns (2010)parent

Comments

SELECT DISTINCT is often a code smell. (Not always.) If you see it, there’s a 70% chance it got slapped on to fix an issue that should have been solved a different way.

SELECT DISTINCT ON is different, and useful.

I had a teacher who had specific rules for exams when we wrote SQL statements:

- For a question worth 2 points, if you use the word "DISTINCT" when it wasn't needed, you lose 0.5 points.

- If you don't use "DISTINCT" when it was necessary, you lose all 2 points.

Oh yes, introducing a little game theory anxiety into exam questions sounds like a wonderful little torturing tool!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.