CASE (searched): SELECT CASE WHEN score>=80 THEN 'A' WHEN score>=60 THEN 'B' END AS grade FROM exams; : Return values conditionally in SELECT

IF(): SELECT IF(active,'Y','N') FROM users; : MySQL-specific ternary conditional

IFNULL(): SELECT IFNULL(phone,'N/A') FROM contacts; : Substitute NULL with alternate value

COALESCE(): SELECT COALESCE(mobile,landline,'N/A') FROM contacts; : Return first non-NULL among
arguments

RETURN: RETURN total; : Exit stored function and return value

SIGNAL: SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Oops'; : Raise custom error inside stored routine

RESIGNAL: RESIGNAL; : Pass on caught error with possible changes

HANDLER: DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; : Define action when specific
condition occurs in stored routine

DECLARE ...: DECLARE v INT DEFAULT 0; : Declare variable or cursor inside routine

LEAVE / ITERATE: LEAVE my_loop; : Control flow inside loops in routines
Previous Next