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...

КОМЕНТАРІ • 29

  • @jleiser22
    @jleiser22 3 місяці тому +1

    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.

    • @ErikDarlingData
      @ErikDarlingData  3 місяці тому

      Aw, thanks for the kind words, and choosing to spend your time with me!

  • @SQLDevDBA
    @SQLDevDBA 3 місяці тому +1

    I appreciate the weather report as well as the Mythbusters BUSTED conclusion!

  • @gustavswanepoel9207
    @gustavswanepoel9207 3 місяці тому +1

    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)

    • @ErikDarlingData
      @ErikDarlingData  3 місяці тому

      Hahaha, thanks Gustav! I do like beer, just the cheap lager variety.

  • @chrismettler136
    @chrismettler136 3 місяці тому +1

    I love your sense of humor

  • @discosammy_
    @discosammy_ 3 місяці тому +1

    Love the query time display under the armpit. 🤣🤣🤣

  • @derkami6722
    @derkami6722 3 місяці тому +1

    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...)

    • @ErikDarlingData
      @ErikDarlingData  3 місяці тому +1

      I have a pair of meat shears that are especially satisfying to cut with 😂

  • @orterves
    @orterves 3 місяці тому

    "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

    • @ErikDarlingData
      @ErikDarlingData  3 місяці тому

      Oh dear. Stick around, I can fix you.

    • @orterves
      @orterves 3 місяці тому

      @@ErikDarlingData give me an example then (and maybe don't try to sound patronising while you do it)

    • @ErikDarlingData
      @ErikDarlingData  3 місяці тому

      @@orterves an example of what?

    • @orterves
      @orterves 3 місяці тому

      @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

    • @ErikDarlingData
      @ErikDarlingData  3 місяці тому

      @@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.

  • @geofftnz
    @geofftnz 3 місяці тому +1

    enjoy your margaritas

  • @bbksvb
    @bbksvb 3 місяці тому +1

    🤣🤣🤣🤣🤣🤣🤣 learn and laugh with this guy! WODs!!!!!!!!!!!!!!!!!!

  • @stephenlawrenson2380
    @stephenlawrenson2380 3 місяці тому +1

    Early?? It’s evening here!! 😉

    • @ErikDarlingData
      @ErikDarlingData  3 місяці тому

      It's sounds like you're in a challenging time zone

    • @stephenlawrenson2380
      @stephenlawrenson2380 3 місяці тому +1

      @@ErikDarlingData anywhere with my family is challenging 😂😂