5 ms·
IDK, "which ZIP codes do we have customers in?" seems like a reasonable thing to want to know
by bandrami 1y ago
IDK, "which ZIP codes do we have customers in?" seems like a reasonable thing to want to know
- mbb70 1y agoThe 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
- sql_nitpicker 1y agodistinct seems like an aggregation to me
- deleted 1y ago[deleted]
- edoceo 1y agocount(id) group by post_code order by 1
- kristjansson 1y agoWhole seconds will have been wasted!
- wvbdmp 1y agoAnti-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.
- RHSeeger 1y ago> 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.
- dleeftink 1y agoPartly 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.
- RHSeeger 1y agoI 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.
- majormajor 1y agoHere 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.
- bandrami 1y agoAh, yeah, you beat me to it. I do reporting, not applications.
- bandrami 1y agoI do reporting, not application development. If somebody wants to know different information I'd write a different query.
- DavidWoof 1y agoIn 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.