Learning MySQL - IF and NULLIF functions

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

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

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

    Started learning SQL, ended up watching some of these quality movies that I haven't seen already. Thank you!

  • @Official.chukwuemekajames
    @Official.chukwuemekajames 8 หลายเดือนก่อน

    Thanks a lot

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

    Hi i have barcode column with 2 type of diffrent data how can i use if statment to diffrent out ( or in other way let mysql decide if code1 enterd do the select and condition ... and so on

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      Tbh, in situations like that I would bring back both columns so, in my server-side code I had the context about which type it was, by having a null column.
      You can use a UNION to join the results of two SELECT statements. Using the WHERE to filter out the NULL values. SELECT the first kind WHERE column 1 is not null UNION SELECT the second kind WHERE column 2 is not null.
      You just have to use the same alias name for all columns.

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

      @@SteveGriffith-Prof3ssorSt3v3 thank u for ur hint ill try it first . Much appreciated

  • @Ahana-q3d
    @Ahana-q3d ปีที่แล้ว

    In IF statement we can use OR OPERATOR or not.
    SELECT movie_id, director, year, if(movie_title LIKE 'H%' OR 'R%', movie_title, NULL) AS `H or R movie name` FROM movies;
    if i run this query i only get the title that starts with H

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

      You can use the OR and AND operators in an IF clause but you have to do it like you would in other programming languages. if(movie_title LIKE H% OR movie_title LIKE R%) each comparison has to be separated. You can't add an OR between each of the values in a list.