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
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.
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
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.
Started learning SQL, ended up watching some of these quality movies that I haven't seen already. Thank you!
Thanks a lot
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
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.
@@SteveGriffith-Prof3ssorSt3v3 thank u for ur hint ill try it first . Much appreciated
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
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.