SQL | Subquery or CTE - Which one to choose? Difference between Subquery and CTE

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

Комментарии • 15

  • @LearnatKnowstar
    @LearnatKnowstar  Год назад +5

    Theoretically, Both subqueries and CTEs should have similar performance.
    SQL Database should be executing both with a similar execute plan.
    Which one do you prefer to use?
    Have you had a scenario where either Subquery or CTE had a better performance over other?
    Please do let us know in the comments below!

  • @oyelowotoyyib925
    @oyelowotoyyib925 Год назад +5

    Thanks for this great video. I prefer CTEs. If someone who is relatively new to SQL, there is a chance that they won't understand a subquery as they would a CTE, especially when they are nested. You may not even know which part runs first. In subquery, you still have to give the query a name even though such name will not be used unlike CTE. It's important to state that any newly generated column in CTE OR subquery must be given an alias for it to run as well.

  • @MyxaTcakatuha
    @MyxaTcakatuha Год назад +4

    As long as both cte and nested do the same which is preferable in terms of performance?

    • @LearnatKnowstar
      @LearnatKnowstar  Год назад

      Theoretically no difference. CTEs are just more readable.

  • @nrk07
    @nrk07 4 месяца назад

    Nice explanation. Thank you

  • @malcorub
    @malcorub 10 месяцев назад

    Thank you, I followed along with Adventure Works SQL practice DB.

  • @DavidSamuelHn
    @DavidSamuelHn Год назад

    Execute plan

  • @mixtape8476
    @mixtape8476 4 месяца назад

    Great tutorial, thank you

  • @manikumar-fx9ud
    @manikumar-fx9ud Год назад

    You speak like fast bowler if you don't mind can speak like spin bowler to better understand

  • @AbhishekKumar-gf4db
    @AbhishekKumar-gf4db Год назад

    I just join one organization as Role Sql Server Developer,
    Mam your video is very helpful for getting my job.
    Thanks mam. ❤
    Keep going on

    • @LearnatKnowstar
      @LearnatKnowstar  Год назад +1

      Many congratulations for your new job ! So glad our videos were helpful. Best wishes to you!

    • @AbhishekKumar-gf4db
      @AbhishekKumar-gf4db Год назад

      @@LearnatKnowstar thanks mam