Correlated Subqueries vs Derived Tables

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ธ.ค. 2024

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

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

    Thank you for such a well done video. I subscribed because I just finished my first mySQL Database Management class. I have to re-do the class and I think your videos will be a big help.

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

    Hey Bert thanks for the amazing tip. I would really appreciate if you can answer this, is there any problem that absolutely requires correlated sub queries that cannot be solved by joins or derived tables.? I don’t like using them because they confuse me. Thanks.

    • @ru2979
      @ru2979 2 ปีที่แล้ว

      True , They are nasty 🥺

  • @robertkorth605
    @robertkorth605 3 ปีที่แล้ว

    I have knowed already it but brilliant presented. Thx

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

    Depending on the original query window function could the trick too... but .. as always... it depends...

  • @zanonilabuschagne7628
    @zanonilabuschagne7628 5 ปีที่แล้ว

    Thanks Bert. I tried your and got different results. I do want to throw another query out, and get your take on it... In the past, I have achieved great performance gains with CROSS APPLY statements with a TOP in it, but when I tested it in this scenario, the results were atrocious. CPU time and reads went through the roof...
    The query is
    select DISTINCT
    o.UserID
    ,S.FirstBadgeDate
    from Badges o
    CROSS APPLY
    (
    select top 1 [Date] as FirstQuoteDate
    from Badges b
    WHERE b.UserID = i.UserID
    Order by b.Date desc
    ) S
    Any idea why it went so wrong?

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

      You’re also selecting the last date, not the first 🤔

  • @ulysses1904
    @ulysses1904 5 ปีที่แล้ว

    Good stuff as always. BTW I have never seen the syntax like (FirstBadgeDate = ) in a select statement. Can you take a moment to explain that, or give it a name so I can research it? I have seen something like that where it was referred to as a quota query but it was in the WHERE clause, like WHERE 2 = (select COUNT(*) from employee EE where E.employeeID = EE.employeeID). I think it was Tony Andrews doing a talk on optimizing DB2 queries where he called it a quota query.

    • @ulysses1904
      @ulysses1904 5 ปีที่แล้ว

      @@DataWithBert Thanks Bert. Looks like I was overthinking it and I didn't recognize it as a column alias.

  • @brendafosmire6519
    @brendafosmire6519 5 ปีที่แล้ว

    Super helpful videos.

  • @KirillBezzubkine
    @KirillBezzubkine 4 ปีที่แล้ว

    nice vid. useful. thx

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

    The Final Solution