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

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 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/

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

  • @deeplysuperficial8132
    @deeplysuperficial8132 2 ปีที่แล้ว +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 2 ปีที่แล้ว +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 2 ปีที่แล้ว +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 3 ปีที่แล้ว +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 2 ปีที่แล้ว

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

  • @ahmadfouad3786
    @ahmadfouad3786 2 ปีที่แล้ว +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 3 ปีที่แล้ว +6

    Last 2 queries can also be done using joins rt?

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

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

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

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

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

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

  • @helovesdata8483
    @helovesdata8483 2 ปีที่แล้ว +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 4 ปีที่แล้ว +1

    thanks really much

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

    great explanation! thank you

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

    thanks!

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

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

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

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

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