Independent vs Correlated Subquery | Advanced SQL Tutorial For Beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ม.ค. 2025

ความคิดเห็น • 36

  • @ankitbansal6
    @ankitbansal6  ปีที่แล้ว +10

    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/course-detail/think-sql-go-from-zero-to-hero-english

    • @jayselokar
      @jayselokar ปีที่แล้ว

      also correlated is more time consuming

    • @UnrealAdi
      @UnrealAdi ปีที่แล้ว +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!

    • @kanikasuneja7777
      @kanikasuneja7777 15 วันที่ผ่านมา

      The link is directing to error page

    • @ankitbansal6
      @ankitbansal6  15 วันที่ผ่านมา

      @@kanikasuneja7777 fixed it. Thank you!

  • @shubh_pokharkar8145
    @shubh_pokharkar8145 หลายเดือนก่อน +1

    This is the best video i have seen on corelated subquery which not only showed how we can solve question with independent subquery , thankyou for such great videos , gratitude🙏🙏

    • @ankitbansal6
      @ankitbansal6  หลายเดือนก่อน

      Glad it was helpful!

  • @DEEPAK-jx5si
    @DEEPAK-jx5si ปีที่แล้ว +3

    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 6 หลายเดือนก่อน

    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 ปีที่แล้ว

    Best video in internet till now explaining the difference

  • @avi8016
    @avi8016 ปีที่แล้ว +2

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

  • @vandanaK-mh9zo
    @vandanaK-mh9zo ปีที่แล้ว +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 7 หลายเดือนก่อน

    Ultimate explanation ❤

    • @ankitbansal6
      @ankitbansal6  7 หลายเดือนก่อน +1

      Thanks a lot 😊

  • @gazart8557
    @gazart8557 ปีที่แล้ว

    Excellent

  • @anjibabumakkena
    @anjibabumakkena ปีที่แล้ว +1

    Hi Ankit, Can You explain Performance tuning.

  • @alkalisblaze
    @alkalisblaze ปีที่แล้ว +1

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

  • @ritudahiya6223
    @ritudahiya6223 ปีที่แล้ว

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

    • @ankitbansal6
      @ankitbansal6  ปีที่แล้ว +1

      NamasteSQL : www.namastesql.com/coding-problems

  • @sandipansarkar9211
    @sandipansarkar9211 ปีที่แล้ว

    finished watching

  • @Shri-RAM-JaiBajrangBali
    @Shri-RAM-JaiBajrangBali ปีที่แล้ว

    Hi Ankit, Please also explain inline queries..

  • @chiranjeevic8384
    @chiranjeevic8384 ปีที่แล้ว

    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 ?

  • @navneethks8677
    @navneethks8677 9 หลายเดือนก่อน

    Very Helpful 🫂🫂

  • @parth_pm16
    @parth_pm16 ปีที่แล้ว

    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

  • @vinodpaluvuri54
    @vinodpaluvuri54 ปีที่แล้ว

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

  • @shruthi.hshruthi3965
    @shruthi.hshruthi3965 ปีที่แล้ว

    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 ปีที่แล้ว

      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 9 หลายเดือนก่อน

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

    • @akhiladevangamath1277
      @akhiladevangamath1277 3 หลายเดือนก่อน

      bcz, select executes after group by, so avg is calculated during the execution of select, group by won't be knowing avg during its execution

  • @sandipansarkar9211
    @sandipansarkar9211 ปีที่แล้ว

    finished watching