SQL Group By: An Explanation and How To Use It

Поделиться
HTML-код
  • Опубликовано: 22 май 2024
  • The SQL GROUP BY keyword is a powerful feature that lets you summarise data from your query into groups.
    This can be helpful to see the number of employees in a department, or the total value of sales per month, and much more. Any time you need "something PER something else", it's often done with an SQL Group By.
    In this video, you'll learn what Group By is, a step-by-step process on how to write one, what happens if you don't include Group By, and some examples.
    Timestamps:
    00:00 Start
    00:09 What is Group By?
    00:30 Sample table
    00:49 First query
    01:34 Group By question
    01:46 Start a Group By query
    02:37 Add an Order By
    03:04 Can we exclude Group By?
    03:59 Using another aggregate function
    /// RESOURCES
    📝 Get my free SQL Cheat Sheets: www.databasestar.com/get-sql-...
    🧭 SQL Roadmap from basics to advanced: www.databasestar.com/sql-road...
    ✍️ Learn how to design a database: databasestar.mykajabi.com/edd
    📧 Contact me here: www.databasestar.com/contact/
    📝 Database Design Exercises: bbrumm.gumroad.com/l/hqsxi
    📝 SQL Practice Questions: bbrumm.gumroad.com/l/ulekqk
    📝 SQL Performance Quick Guide: bbrumm.gumroad.com/l/fcvny
    📝 Ultimate SQL How-To Guide: bbrumm.gumroad.com/l/oqggau
  • НаукаНаука

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

  • @goobygoobdisney
    @goobygoobdisney 10 месяцев назад +36

    I don't usually comment on tutorial videos, but this video is so clear I just want you to know how helpful you are for beginners like me

  • @user-iv9sh9fc3c
    @user-iv9sh9fc3c 10 дней назад +1

    you are definitely a database star. Thank you

  • @rickvazquez6578
    @rickvazquez6578 Год назад +12

    Mate you clarified something for me, I was wondering why I always had to add every other column I had to group by :) plenty helpful keep up the great tutorials!😃

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

      Glad it helped you understand the concept further!

  • @ordinaryperson-my7qr
    @ordinaryperson-my7qr Год назад +1

    thanks sooooo much dude
    i NEVER wrapped my head around how this works
    now i am crystal clear :)

  • @COOKINGBIRD
    @COOKINGBIRD 10 месяцев назад +2

    Your SQL video was exactly what I needed. Thank you for explaining it so clearly. 😄🎬💻🔍

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

      Thanks, glad you liked it!

  • @ZenSpires
    @ZenSpires Год назад +2

    Thank you for explaining it in such a simple way :)

  • @akanirokingsley3304
    @akanirokingsley3304 Месяц назад +1

    your explanations resonates with me on a deep level.

    • @DatabaseStar
      @DatabaseStar  Месяц назад

      This makes me happy. I’m glad the explanations help you!

  • @khawar1690
    @khawar1690 Месяц назад +1

    Very well explained. Aggregated function was helpful to me. Thank you

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

    This was helpful and clear, thank you! I liked your group by question, because I tend to create a question like that when I'm struggling to formulate the correct query.

  • @thebigcheese1153
    @thebigcheese1153 2 месяца назад +1

    Thanks for actually explaining it.

  • @sebastianhernandez9631
    @sebastianhernandez9631 6 месяцев назад +2

    I'm preparing for DP-900 exam and I was having a hard time with the Group By statement and aggregate functions. This video has helped me understand it perfectly. Thanks! Subscribed.

    • @DatabaseStar
      @DatabaseStar  6 месяцев назад

      Thanks! I'm glad the video helped you understand it.

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

    Super helpful. First slide's visual really helped...

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

    very detailed. clear. beautiful
    thanks ALOT
    really helpful

  • @higiniofuentes2551
    @higiniofuentes2551 7 месяцев назад

    Thank you for this very useful video!

    • @DatabaseStar
      @DatabaseStar  7 месяцев назад +1

      No problem, glad you liked it!

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

    awesome most easiest explanation. Thanks man

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

    very helpful; thank you!

  • @Mike-vj8do
    @Mike-vj8do 6 месяцев назад

    real good video, thank you!

  • @DCh-ks6ug
    @DCh-ks6ug 3 месяца назад +1

    that waaaaas veeeeery helpful thaaaaaank you

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

    👋 Bravo!
    A very well-explained demo!

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

      Thanks!

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

      @@DatabaseStar....... You're very welcome!
      Can you please make a crash course about "MySQL for Advanced Data Analytics"?

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

    Excellent video !

  • @leonsant-jennings7417
    @leonsant-jennings7417 Год назад

    Cheers boss, I knew I had to use Group By but I didn't fully understand why.

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

    thanks it really helped

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

    Nice video! Your indentation hurts me, but thank you for this video; It is very well presented!

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

      Thanks! Do you prefer a different style of indentation for SQL code?

  • @vaylx2253
    @vaylx2253 2 года назад

    Thanks for that.

  • @user-vz7qd1br5o
    @user-vz7qd1br5o 2 месяца назад

    thank you.

  • @Entertainmentmod
    @Entertainmentmod 2 года назад

    Very good information

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

    Thank you 👍

  • @dragoneer8756
    @dragoneer8756 6 месяцев назад

    Good to know, most important part was that the field selected should be in the group by clause. THey completely left that out in class

    • @DatabaseStar
      @DatabaseStar  6 месяцев назад

      Glad you liked the video. Can’t believe they left that out of your class!

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

      @@DatabaseStar It was a very rushed class tbh. Teaching finished at the beginning of November so I'm self-studying for finals😅😅

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

    My only question is if you have 3 columns in the Select Statement with an aggregate function, for example, is it mandatory to always include all 3 columns in the group by clause? And if not, then how do we know which of the 3 columns must be included?

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

      Good question. Yes, it's mandatory to include all three columns in the Group By clause. If you don't, you'll get an error about columns in the Select not in the Group By (the exact error will depend on the database vendor).
      The only exception is some versions of MySQL allow you to have a mismatch between the Group By and the Select. But you'll get a result that won't be correct, such as showing the first group only but the aggregate function on all rows.

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

      @@DatabaseStar Thanks for the awesome reply! I just subscribed.

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

    Can you please give an example with two tables that have many to many relationships

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

    Thanks

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

    I honestly gonna die with this language :")

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

    🙌

  • @Entertainmentmod
    @Entertainmentmod 2 года назад

    Can you t sql vedios