News for hackers. Stuff that matters.
Re:SQL Anti-Patterns You Should Avoid by bandrami on Saturday October 18, 2025 @11:47AM (#45628236)
IDK, "which ZIP codes do we have customers in?" seems like a reasonable thing to want to know
Re:SQL Anti-Patterns You Should Avoid by mbb70 on Saturday October 18, 2025 @11:51AM (#45628274)
The very next ask will be "order the zipcodes by number of customers" at which point you'll be back to aggregations, which is where you should have started
Re:SQL Anti-Patterns You Should Avoid by edoceo on Saturday October 18, 2025 @12:16PM (#45628435)
count(id) group by post_code order by 1
Re:SQL Anti-Patterns You Should Avoid by sql_nitpicker on Saturday October 18, 2025 @11:59AM (#45628346)
distinct seems like an aggregation to me
Re:SQL Anti-Patterns You Should Avoid by kristjansson on Saturday October 18, 2025 @12:24PM (#45628489)
Whole seconds will have been wasted!
Re:SQL Anti-Patterns You Should Avoid by wvbdmp on Saturday October 18, 2025 @12:26PM (#45628505)
Anti-Patterns You Should Avoid: overengineering for potential future requirements. Are there real-life cases where you should design with the future in mind? Yes. Are there real-life cases where DISTINCT is the best choice by whatever metric you prioritize at the time? Also yes.
Re:SQL Anti-Patterns You Should Avoid by RHSeeger on Saturday October 18, 2025 @12:49PM (#45628665)
> Are there real-life cases where DISTINCT is the best choice by whatever metric you prioritize at the time

Indeed, along that line, I would say that DISTINCT can be used to convey intent... and doing that in code is important.

- I want to know the zipcodes we have customers in - DISTINCT

- I want to know how many customers we have in each zipcode - aggregates

Can you do the first with the second? Sure.. but the first makes it clear what your goal is.

Re:SQL Anti-Patterns You Should Avoid by dleeftink on Saturday October 18, 2025 @02:51PM (#45629559)
Partly in jest, but maybe we need a NON-DISTINCT signaller to convey the inverse and return duplicate values only.

SOMEWHAT-DISTINCT with a fuzzy threshold would also be useful.

Re:SQL Anti-Patterns You Should Avoid by RHSeeger on Saturday October 18, 2025 @05:03PM (#45630326)
I hear you. It's not all _that_ uncommon for me to query for "things with more than one instance". Although, to be fair, it's more common for me to that when grep/sort/uniqing logs on the command line.
Re:SQL Anti-Patterns You Should Avoid by majormajor on Saturday October 18, 2025 @01:07PM (#45628796)
Here we start to get close to analytics sql vs application sql, and I think that's a whole separate beast itself with different patterns and anti-patterns.
Re:SQL Anti-Patterns You Should Avoid by bandrami on Saturday October 18, 2025 @05:04PM (#45630330)
Ah, yeah, you beat me to it. I do reporting, not applications.
Re:SQL Anti-Patterns You Should Avoid by bandrami on Saturday October 18, 2025 @05:02PM (#45630321)
I do reporting, not application development. If somebody wants to know different information I'd write a different query.
Re:SQL Anti-Patterns You Should Avoid by DavidWoof on Saturday October 18, 2025 @03:50PM (#45629926)
In OP's defense, "becoming suspicious" doesn't mean it's always wrong. I would definitely suggest an explaining comment if someone is using DISTINCT in a multi-column query.