logoalt Hacker News

procaryote • today at 7:11 AM • 2 replies • view on HN

I've generally started to treat use of SELECT DISTINCT as a warning flag, as it's very common that it indicates bad code

Some use it because they don't understand uniqueness constraints and try to fix it in post so to say. Some use it because they forgot a join condition and are absolute amateurs. Some use it because it fixed a problem for them once and now they add it everywhere

These people seem to outnumber the people who use SELECT DISTINCT in a well thought out manner


Replies

photios • today at 8:10 AM

Yeah, people have been advising against DISTINCT for ages. I guess that piece of common wisdom somehow got lost in this age of AI wonders. :D

Dylan16807 • today at 7:16 AM

It's definitely a warning flag if you're applying it to full-ish rows. This situation seems much more innocuous to me.