How To Solve SQL Problems

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 มิ.ย. 2024
  • In this video I will be solving all of the SQL problems in my Learn SQL GitHub repository. I will be explaining my thought process and the solution as I go to help build a stronger understanding of why I do certain things. If you haven't already watched my Learn SQL In 60 Minutes video or done the exercise problems first, make sure to checkout the links below and do both those first.
    IMPORTANT: Exercises Worksheet Repository:
    github.com/WebDevSimplified/L...
    Learn SQL In 60 Minutes:
    • Learn SQL In 60 Minutes
    Outline:
    [00:29] - Problem 1
    [02:40] - Problem 2
    [03:20] - Problem 3
    [04:30] - Problem 4
    [05:57] - Problem 5
    [07:42] - Problem 6
    [10:24] - Problem 7
    [11:47] - Problem 8
    [13:52] - Problem 9
    [15:05] - Problem 10
    [15:54] - Problem 11
    [17:36] - Problem 12
    Twitter:
    / devsimplified
    GitHub:
    github.com/WebDevSimplified
    CodePen:
    codepen.io/WebDevSimplified
    #SQL #LearnSQL #MySQL

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

  • @RameenFallschirmjager
    @RameenFallschirmjager 4 ปีที่แล้ว +99

    Real heroes are not those who go to wars or pick a fight or engage in any destructive activity. Real heroes are those who make, build, create and educate. These men and women make world a better place. Our culture should reinvent itself. We need to reconfigure our culture in a way that movies and books and comic books depict this kind of heroism. Kyle, you are a real hero. I appreciate your great work and I hope you prosper. People like you deserve to be powerful and rich, because you contribute to others' well being with your power.

  • @wandersonhelmer1810
    @wandersonhelmer1810 ปีที่แล้ว +15

    I have just finished your exercises and came by to take a peek whether or not I was in the right direction. Sure enough I did a pretty decent job thanks to your teaching. I cannot express how much I very much appreciate your job here on youtube. Thank you ever so much and I hope your channel grow atomically!

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

    Thanks Kyle! Watching this after working through the problems on my own helped solidify SQL foundations. Thank you for all your hard work!

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

    The SQL series is awesome. Just watched it to get a quick refresh of MySQL, and really feeling confident in it now. Thanks Kyle!

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

    This was incredibly helpful and awesome, thank you Kyle!

  • @edimathomas-cr4km
    @edimathomas-cr4km ปีที่แล้ว +2

    This was incredible. As a beginner, some of the exercises were tough but I'm glad I completed all the exercises. Surprisingly, 12 was among the easiest for me.

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

    You sir, are gonna go lengths! Thank you and all the very best!

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

    What a great lesson! Thanks!

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

    learning anything is possible with a great teacher, i ahve been trying to understand the structure of the SQL programming until i watched your 60mins video and now i am able to solve all the questions that you explain here. thank you very much, great work, great quality!

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

    I can't believe this is free! Thank you so much!

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

    Can't appreciate this more, thanks a lot SQL hero!

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

    using sql every day, you picked here some nice examples to start off! 👍😉

  • @kunalpandey7189
    @kunalpandey7189 3 ปีที่แล้ว +5

    3rd question can be done simply by--
    select min(release_year) from albums

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

    Your tuts are the best on YT

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

    You are absolutely incredible. Thank you

  • @roshanshah5831
    @roshanshah5831 3 ปีที่แล้ว +15

    Hello this one was really good, Could you make some more of SQL stuff on your channel which focuses on advanced concepts or practise?

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

    Nice tutorial, teached me a lot of good songs.

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

    What an amazing video. It was really helpful to learn and understand the SQL queries. Thank you so much for this.

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

    Thanks for the lessons!
    I've done all exercises, except 3 and 5))

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

    In the repo You have a misspel in the column name: instead of "length" it is "lenght"
    Thx for the 60 min intro and for the exercises!
    You have much more structured lecture and easily percieved speach than other SQL teachers on youtube

  • @infamismworldwild6248
    @infamismworldwild6248 23 วันที่ผ่านมา

    Thank you so much, this was really beneficial

  • @bob-zl5nq
    @bob-zl5nq 2 หลายเดือนก่อน

    Thang you so much❤❤❤ you've just saved my midterm😊

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

    Loved these questions! Can you make a new video on how to write optimized queries?

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

    loved the way you explain that! thanks a lot ;)

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

      Ohhh “ ;) “ , she tryna flirt with you bro

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

    oh my gosh your channel is so amazing

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

    thank you so much for this!

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

    Is it normal to group by a column that is not specified in the select statement?
    I saw that here 7:13 at line 4. also at 10:31 at line 7

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

    Hi, i'm asking for the auto_increment statement ! Are we can replace it with the identity statement ??

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

    Nice thanks ❤

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

    thanks sir !

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

    Hello, I am new to this so this might be a naive question but can we solve ques-3 by using the 'Having' clause?

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

    Off topic but great taste in music

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

    You are 10/10 explaining SQL and breaking it down pretty well. This however, is really not complicated at least "solving a problem", unrealistic example by all means wish you would do more to explain the in depth 3 table inner join, with nested queries etc

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

    Why do you use periods when you are already specifying where the column comes from? I don't understand why and how to use it really...

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

    for question 11, I got an error when I also selected column songs.name. Is there a reason for that? Thanks for any opinions

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

    Just as a side thought, I would think that the better-optimized query would be using WHERE instead of HAVING to define the filter. Because where would take just a limited number of records, and having would consider all of them, so it would be significantly faster. wouldn't it? Again, it is just an opinion :)

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

    Failed to execute SQL script statement of class path resource
    Why and when its come
    Please answer this ..

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

    Hey, Kyle. In #5, in the GROUP BY albums.band_id line, is the 'albums.' part necessary? It seems to work without it.

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

      It will work without it. The only time you need the table name before the column is if two tables in your query have a column with the same name.

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

      @@WebDevSimplified Gotcha

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

    Hey Followed all the instructions but its not letting me create the songs table, giving me an error code 1063 : incorrect column specifier for column 'name'

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

    is there a problem here requiring analytic not practice how to input and where to etc. Like real world problem

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

    for the 3rd query can't we just write it as SELECT * FRFOM ALBUMS WHERE RELEASE_YEAR=MIN(RELEASE_YEAR);

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

    In the exercise 11, his returning the longest song duration for each album, without decimal places, wich means, his auto rounding the values and i don´t know why ?
    Can someone give me a tip why ?
    The Query is 100% rigth btw

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

    in the last question can we group by band.name

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

    at 10:27 whats the difference between doing AS Name and AS 'Name'?

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

    i cant solve those tasks based on the tutorial you provided, sure i can google similar cases and copy, this is so frustrating

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

    Super sir..i am beginner.. please provide any pdfs of SQL .to learn

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

    In exercise #6 when you return the album name as Name (albums.name AS Name) shouldn't Name has apostrophe since it's a VARCHAR variable?

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

      If the alias has only one word apostrophes are not needed

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

      AS Something means that you are giving that column other name than its original name. In this case its original name is name with small letters. On the output however it will appear as Name with cap N. It has nothing to do with the value type of the column.
      You would need apostrophe if more than one word is used for renaming or the word used is somewhat reserved by he SQL syntax . In that same example it puzzles me though why Kyle uses apostrophe for Duration.

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

      @@mocococo2877 hey, man , thanks for the huge help for those of us who asked in comments, appreciate
      do u have a discord or skype?

  • @vickia.9641
    @vickia.9641 ปีที่แล้ว

    Mr. @kyle, please create a training for HAR file training to be analyzed. Thanks in advance...

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

    help, my mySQL is being stupid. I copied and paste your codes into mysql and it wont run it for some reason.

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

    I have a problemin my charging patient table .the data insert in the table through 8 forms.....the sequence which is define for this table jumped ..and escape the values...the structure of the sequence having min 1 and mix 10 lakh with nocash .. so the problem is that the sequence is jump ..it miss values in the table...whts should be do??? How to fix this problem ???.. i think the problem is in the forms where data is inserted in the table ... Any one help to fix my problem???

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

    In 11th question select longest song of each album. how can we display name of that longest song also.

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

    I think in Oracle 'Group by ' doesn't work like in MySQL. Solution 4, 5, 6 doesn't work.

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

    Is it in SQL servwr or in my SQL ?

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

    Why there is no table representation? All the way through the video till the last minute i realised there are 3 tables instead of 2

  • @kwamedaniels1888
    @kwamedaniels1888 4 วันที่ผ่านมา

    Please send me the link to the questions

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

    am i the only one getting 'Error while executing SQL query on database 'album': near "AUTO_INCREMENT":'?

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

      You're probably using a different SQL, try using "IDENTITY (1, 1)" instead of that

  • @user-ou2sg9gp4z
    @user-ou2sg9gp4z 8 หลายเดือนก่อน

    Hi sir
    Your video is useful for
    Please c language codeing tell me sir

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

    14:21 can we use "drop" instead of delete?

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

      DROP in SQL means that entire table will be dropped (the table will not exist after this command) with all data in it. And there is no "Are you sure ..." :)
      Read about SQL TRUNCATE vs DELETE vs DROP.

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

    value otherwise is not a member of org.apache.spark.sql.dataframe
    Please give me the correct answer

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

    I solved #12 using nested queries and noticed that your answer does not display that band "Dream Theater" because they have no songs. I believe this is because your joins are left joins and not outer joins

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

      A left join is an outer join, aka left outer join.
      He uses inner joins. That's why. A simple (just) join is an inner join. At least in MySQL...
      If he also had a where clause, sometimes the where clause can turn a left join into an inner join. I don't he would ever cover an issue like that...

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

    For Problem 7:
    SELECT * FROM albums
    WHERE release_year IS NULL;
    UPDATE albums
    SET release_year =1986
    WHERE id =4;
    You used UPDATE specifically for where the key was id=4, but what if we had a larger data set and we wanted multiple id's. Like id=4, id =10, id=38, id=50. Is there a way in which we could find these id's without manually searching for them and manually putting in id values to update.
    Thank you for these videos! They are very clear and helpful!

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

      You can use anything in the where section of your update. For example if you wanted to update all albums with a release_year of 2000 you could say WHERE release_year = 2000

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

      I think it is possible to update many rows at once but only it one fixed year. Like all of them to have release_year = 1986.
      If you want however to have release_year = 1989 for id 4 and release_year=1999 for id 10 ... etc. then I do not think it would be possible other than manually.

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

    900 th like "Me" 😁😁

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

    Master brenches are called Main branches for a good reason

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

    Looks like many of us are having some issues with #5. Can anyone help me understand why the COUNT(albums.id) doesn't read COUNT(albums.band_id)?? It makes more sense to me and returns the same result...? Way to go everyone. Keep it up!

  • @AlejandroGonzalez-sw7jz
    @AlejandroGonzalez-sw7jz ปีที่แล้ว +4

    Hi, I get this error in exercise 5, even when I use the solution code, did anyone get the same?
    Error Code: 1055. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'record_company.bands.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

    • @bitetheapple8
      @bitetheapple8 ปีที่แล้ว +6

      I had the same error & then changed the group by and it worked
      SELECT b.name AS 'Band Name'
      FROM bands AS b
      LEFT JOIN albums AS a ON b.id = a.band_id
      GROUP BY b.id
      HAVING COUNT(a.id) = 0;

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

      @@bitetheapple8 I had the same error. Thanks for the solution. I also used a different query.
      SELECT b.name AS 'Band Name'
      FROM bands AS b
      LEFT JOIN albums AS a
      ON b.id = a.band_id
      WHERE a.band_id IS NULL;

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

      @bitetheapple8 Perfect. Thank you for sharing 👍😁

  • @GauriSuralkar-sz3zn
    @GauriSuralkar-sz3zn ปีที่แล้ว

    I did it! ^_^ Imsh

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

    For 7th problem,
    Can someone verify this:
    Update albums
    Set releaseyr = 1986
    where id in {
    Select id from albums where releaseyr is null
    } ;

    • @Unknown-840
      @Unknown-840 ปีที่แล้ว

      it works but it's not ideal, your filtering through the table twice
      you should do it like this:
      Update albums
      Set releaseyr = 1986
      where releaseyr is null;

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

    I have a problem for you to solve.
    Let's say you have a temp table with 2 million records that contains some fields. One of the fields contains one of a couple dozen formulas as a string. The couple dozen formulas all occur in some of the 2 million records... The formulas references other fields in your table and might also use a multiplier. I.e. "HrsPerDay*1", "HrsPerDay*1.25", "HrsPerDay*1.5", HrsPerWeek/5*1.25*fte", etc.. There is also a field that has to be calculated that holds the formula's result. How do you do this?
    The formulas need to be evaluated as quickly as possible. In less than a minute. 10 seconds would be good...

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

    How do we save data from API calls to our DB? make a practical video showing how JS + SQL work and link between backend and front end, you can do a short simple one not 1h project example. Do it with a web component if you're a god

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

    Well, trying to learn this stuff is just a heavy blow on my self-esteem and constantly being reminded that I'm not very quick at learning

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

      good vids though

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

      @@DDismas Patience is key. One year ago, I was terrible at everything but right now I am getting things better. Still have lots of work to do but I can see my progress. Don't worry man and keep on learning!

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

      I am more than 10 years in programming and have positioned myself between 6 or 7 on the 0 to 10 scale. It is based on infinite number of problems I have researched and while I learn, try and find the solution I also see how other guys understand it
      But I still have most of my days feeling bad about my speed of work at my work place.
      Philosophers say it is number one virtue of sanity to question yourself and doubt yourself.

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

    “Let my DBA have a look at my query”
    Usually he gets so frustrated he does it with me on the spot.
    Now a year later im the persons newbies ask for help with SQL queries.

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

    Couldn't solve 5, 7 and 12

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

    Very hard to understand for a complete beginner😥

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

      Check out alex the analyst on TH-cam.

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

    I will give one simple problem can you solve

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

    The video is good and educational but the lecture is very fast when lecturing.

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

    Wanted to comment, on problem #5. Idk if the system was updated or different keywords were used, but the function didn't go through and it gave me an error.
    However I read through it and changed the 'GROUP BY' command to 'bands.name' instead of 'albums.band.id' which made the query look like this:
    SELECT bands.name AS 'Band Name'
    FROM bands
    LEFT JOIN albums ON bands.id = albums.band_id
    GROUP BY bands.name
    HAVING COUNT(albums.id) = 0;
    Just in case if anyone else had problems like I did.

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

      Thank you for this

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

      thanks, i was confused by answer on githab

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

    On Excercise 6 I get this error even when I copy & paste your solution: "17:25:08 SELECT albums.name as Name, albums.release_year as 'Release Year', SUM(songs.length) as 'Duration' FROM albums JOIN songs on albums.id = songs.album_id GROUP BY songs.album_id ORDER BY Duration DESC LIMIT 1 Error Code: 1054. Unknown column 'songs.length' in 'field list' 0.000 sec: