3 ms·
I don't even understand the thought process that would have led to the non-optimal query. It would simply never occur to me to use anything other than UNION ALL
by jiggawatts 6y ago
I don't even understand the thought process that would have led to the non-optimal query. It would simply never occur to me to use anything other than UNION ALL for this kind of scenario, because it is the only appropriate translation of the english-language business request into a SQL query.
- dwd 6y agoAfter working 20+ years in the industry I'm always surprised by the aversion (or lack of thought) to draw up a Venn diagram on a white board to visualise the relation, let alone then write it out using set notation.
- avereveard 6y agoProbably the result of some early attempt at either sorting or removing duplicates
- robertlagrant 6y agoIt could be that the query was gradually modified. It's pretty simple to spot the union when the problem's being focused on, laid out nicely in a blog post, and the answer already given!