Independent vs Correlated Subquery | Advanced SQL Tutorial For Beginners

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

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

  • @ankitbansal6
    @ankitbansal6  9 месяцев назад +8

    99 percent of the time you can solve a problem using an independent query with a combination of cte and window functions.
    As the correlated sub queries are not so performance always try to avoid them.
    If you are looking to learn SQL from basic to advanced with lots of practice material and projects do consider my 0 to hero SQL course :
    www.namastesql.com/courses/SQL-For-Analytics-6301f405e4b0238f71788354

    • @jayselokar
      @jayselokar 9 месяцев назад

      also correlated is more time consuming

    • @UnrealAdi
      @UnrealAdi 9 месяцев назад +1

      Hi @ankitbansal6, the script provided don't match with the result set of the emp table! Fixing it may be useful.
      Also, thanks for the incredible content as usual!

  • @DEEPAK-jx5si
    @DEEPAK-jx5si 9 месяцев назад +2

    Here is my Solution
    select * from
    (select *,
    avg(salary) over(partition by department_id ) as avg_dep_sal
    from emp) e
    where e.avg_dep_sal < e.salary

  • @shivammishra-mk9jp
    @shivammishra-mk9jp 2 месяца назад

    I saw multiple videos on this topic, but trust me guy's no one can simplify the lang. or concept other than Mr. Ankit Bansal. Respect you sir for a reason 🙏🙏 thanks a lot❤

  • @prajjwaljaiswal3419
    @prajjwaljaiswal3419 9 месяцев назад

    Best video in internet till now explaining the difference

  • @avi8016
    @avi8016 9 месяцев назад +2

    Great explanation 💯
    Would you like more videos like this where you cover important topics.
    Thankyou!!😊

  • @vandanaK-mh9zo
    @vandanaK-mh9zo 8 месяцев назад +1

    why we need subqueries: when the required format of the data is not given/not available, then we need to derive it and the join it back with the main data.
    Independent Subquery - 1. it can be run independently 2. it runs only once
    Correlated Subquery - 1. It cannot run independently because it has the reference of the main query 2. it runs for every record of the main query

  • @ayyappansri
    @ayyappansri 3 месяца назад

    Ultimate explanation ❤

  • @parth_pm16
    @parth_pm16 9 месяцев назад

    Solution using "AVG(salary) over ()"
    Solution:
    select *
    from (select *
    ,avg(salary) over(partition by department_id) avg_dep_salary
    from emp_6_dec) s
    where salary>avg_dep_salary

  • @anjibabumakkena
    @anjibabumakkena 9 месяцев назад +1

    Hi Ankit, Can You explain Performance tuning.

  • @gazart8557
    @gazart8557 9 месяцев назад

    Excellent

  • @alkalisblaze
    @alkalisblaze 9 месяцев назад +1

    Hey @ankitbansal6, you missed a paranthesis ')' in your insert statement while inputting for Ankit's entry.

  • @Shri-RAM-JaiBajrangBali
    @Shri-RAM-JaiBajrangBali 9 месяцев назад

    Hi Ankit, Please also explain inline queries..

  • @sandipansarkar9211
    @sandipansarkar9211 9 месяцев назад

    finished watching

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

    Very Helpful 🫂🫂

  • @ritudahiya6223
    @ritudahiya6223 8 месяцев назад

    @ankit bansal please tell for analytics point of view which platform is better for practicing sql.. Leetcode or data lemur?

  • @chiranjeevic8384
    @chiranjeevic8384 9 месяцев назад

    Hi Ankit, is the PLSQL concepts like stored procedures, triggers important for a data engineer ? If it's important, can you pls make a vedio on it ?

  • @vinodpaluvuri54
    @vinodpaluvuri54 9 месяцев назад

    Hi Ankit, can you let us know when to use correlated subquery.

  • @shruthi.hshruthi3965
    @shruthi.hshruthi3965 9 месяцев назад

    Hi @ankitbansal6 i m new to sql can anyone explain why cant we use
    select department_id ,avg(salary) as avgsal
    from emp
    groupby department_id
    having salary> avg(salary)

    • @hamzarahman7763
      @hamzarahman7763 9 месяцев назад

      if you want to solve this way you should Learn Self Join first...
      Hint: you have to separate avg(salary) into different intermediate table, because code don't know whats is avg(salary)..

    • @suriyas6338
      @suriyas6338 5 месяцев назад

      Hey,
      To know this, please get the understanding of sql order of execution. You'll be able to understood

  • @sandipansarkar9211
    @sandipansarkar9211 9 месяцев назад

    finished watching