We Learn SQL #10 | Subqueries with the IN operator in SQL

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • Learn SQL Subqueries with the IN operator. This is extremely helpful, thanks to which you will write better and clearer SQL queries.
    If you want to learn or practice SQL, check out learnsql.com/.
    Hello, my name is Adrian. Welcome to another video in the series about SQL basics. We already know simple subqueries that return a single value. We talked about them in the previous video. This time, we’re going to tackle slightly more advanced examples, where a subquery returns more than one value. So, without further ado, let’s get started!
    Let’s learn SQL together!
    👌 Subscribe to our channel and leave a comment!
    👌 Do you want to learn SQL? Go to LearnSQL.com and choose the course or track that is best for you!
    👌 Join us on Facebook: / welearnsql .
    🔊 Music: www.bensound.com/

Komentáře • 17

  • @deeplysuperficial8132
    @deeplysuperficial8132 Před 2 lety +11

    How do you not have more views and subscribers? Your explanation on subqueries is by far the best out of the 5 others I've watched.

  • @leecheeann493
    @leecheeann493 Před 2 lety +8

    I think the answer in 4:20 has one error.
    In the table *city*, we do not have column named 'city_id'.
    The correct one is
    SELECT * FROM city
    WHERE id IN (SELECT city_id FROM university WHERE rank

  • @patriciogaray2589
    @patriciogaray2589 Před 2 lety +5

    Muy buena explicación, solo un error en el código de
    "SELECT * FROM city WHERE city_id IN (...) ”
    Ya que la tabla city, no tiene la columna city_id, si no que la columna “id”, entonces la query correcta debiese ser:
    "SELECT * FROM city WHERE id IN (...);
    Propongo usar la convención de nombres para las T-SQL PascalCase.
    Muchas gracias por los videos! Son muy buenos. Exito en tu canal.

  • @arber10
    @arber10 Před 3 lety +4

    Very good explanation.
    The last example has a small flaw.
    ▶ "SELECT * FROM city WHERE city_id IN ..." instead of "... WHERE id IN ..."

    • @1970shikha
      @1970shikha Před 2 lety

      Yes, this I too noticed and it should be rectified.
      But i must say 'explained very well'.

  • @ahmadfouad3786
    @ahmadfouad3786 Před 2 lety +6

    I think there is a mistake in the second query. It should be:
    Select *
    From city
    WHERE id IN
    (SELECT city_id FROM university WHERE rank

  • @suyashsrivastava3671
    @suyashsrivastava3671 Před 3 lety +6

    Last 2 queries can also be done using joins rt?

  • @Flyxes
    @Flyxes Před rokem

    Low amount of views and such an extraordinary level of explanation, thank you!

  • @sogolsaremi6306
    @sogolsaremi6306 Před 3 lety

    Very helpful! Great work. I hope you keep working here and make more videos.

  • @ymnop9652
    @ymnop9652 Před 2 lety +1

    Shouldnt we use WHERE id(insted of city_id)? 4:23

  • @helovesdata8483
    @helovesdata8483 Před 2 lety +1

    I guess the only challenge in the last query would be if we needed to show the actual rankings column for the output

  • @geofreykweyu6902
    @geofreykweyu6902 Před 4 lety +1

    thanks really much

  • @Maxpointgoldbuyersmeadowbrook

    great explanation! thank you

  • @robertwide6592
    @robertwide6592 Před 2 lety

    thanks!

  • @IvanDerzhyloCIQ
    @IvanDerzhyloCIQ Před 9 měsíci

    is't better use distinct in subquery?
    `SELECT * FROM city WHERE id IN (SELECT DISTINCT city_id FROM university WHERE rank

  • @terb44
    @terb44 Před rokem

    Is the "IN" operator just a better way of listing multiple results instead of using "OR" repeatedly?
    i.e. you could have just used
    WHERE
    country = "USA" OR "UK"

  • @milad12321
    @milad12321 Před 6 měsíci

    The result in 2:12 only should have one column "ID". Learn yourself sql before teaching.