Why You Should Avoid People Who Tell You To Avoid Subqueries In SQL Server
Вставка
- Опубліковано 5 вер 2024
- Become a member! / @erikdarlingdata If you like what you see here, you'll love my advanced performance tuning training:
training.erikd... Click here for 50% off a health check: training.erikd...
What I love about Erik's videos, is that he makes me think about solving performance problems differently, I rarely write subqueries in the SELECT, but this video will make me (re)consider this approach when (re)writing queries for performance. The entertainment is always a great bonus as well. Thanks Erik for what you do for the SQL Server community.
Aw, thanks for the kind words, and choosing to spend your time with me!
I appreciate the weather report as well as the Mythbusters BUSTED conclusion!
Busting makes me feel good.
Enjoy them margaritas and Martinis (sans olives) Erik. Great learning from this. Thank you for sharing your SQL Server knowledge with the rest of us SQL people (beer drinkers that some of us are)
Hahaha, thanks Gustav! I do like beer, just the cheap lager variety.
I love your sense of humor
I’m glad someone does 😃
Love the query time display under the armpit. 🤣🤣🤣
Right where it belongs!
You can use a knife go sharpen your pencil. You can cut your meat with scissors. You can write queries with subqueries. Just because you can, doesn't mean you always should. But i appreciate you bring out the correct "why is my query slow". That's a good lesson to learn for everyone.
Maybe people do confuse using functions that contain queires as a subquery generalizion and always think subqueries get executed for each row solo. (They probably would be if it werent for the query optimizer...)
I have a pair of meat shears that are especially satisfying to cut with 😂
"Avoid distinct" is good advice because distinct is often used as a crutch by people who haven't taken the time to understand the data model.
Similar with subqueries - for me it's less about performance, more about clarity of the query
Oh dear. Stick around, I can fix you.
@@ErikDarlingData give me an example then (and maybe don't try to sound patronising while you do it)
@@orterves an example of what?
@ErikDarlingData an example of a video that can "fix me". But account for the fact that I say avoid distinct, not never use distinct, and that it's advice to people new to SQL because they use it when they shouldn't, not when they should. Similarly with subqueries (specifically in select) - they use them as a crutch, instead of thinking through their queries
@@orterves I can point you to a few videos where using distinct or union (instead of union all) can yield performance improvements. But you don’t care about performance, so that probably wouldn’t do anything for you since you said you don’t care about it. The problem with meme advice like ~avoid distinct~ is that even when you wriggle about and add some flowery qualifiers to it is that you don’t give anyone an example of when it’s okay, or better than the alternatives, or how “understanding data models” rather than linguistic elements (like using exists instead of joins) can help them avoid using distinct unnecessarily. Perhaps it’s time for you to start producing your own content where you can explain things in a way that makes you happy.
enjoy your margaritas
In it to win it!
🤣🤣🤣🤣🤣🤣🤣 learn and laugh with this guy! WODs!!!!!!!!!!!!!!!!!!
I AM THE WOD!
Early?? It’s evening here!! 😉
It's sounds like you're in a challenging time zone
@@ErikDarlingData anywhere with my family is challenging 😂😂