Posts

Showing posts with the label IF and ELSE

Know Your MYSQL: IF and ELSE

Image
We can IF and ELSE control structure in two ways in MYSQL. If you are creating a procedure and you want to use IF and ELSE control structure in your stored procedure. IF syntax : IF search_condition THEN statement_list [ELSEIF search_condition THEN statement_list] … [ELSE statement_list] END IF For example : MYSQL > BEGIN > IF (userId <> ”) && (userId <> 0) then > SELECT * FROM user_table where user_id  = userId; > END IF; > END In this case this procedure will run the select statement only if userId is not equal to ” and 0 Next example : MYSQL > BEGIN > IF (userType = “emp”) then > select * from emp_table where user_id = userId; > ELSE IF (userType = “Admin”) > select * from admin_table where user_id = userId; > ELSE > select * from user_table where user_id = userId; > END IF; > END In this case we are first checking the the type of userType by comparing it with d...

Popular posts from this blog

How to Secure Session Management in Node

Angular 9 - User Registration and Login Example & Tutorial

How to download a file using command prompt (cmd) Windows?