MySQL Case

MySQL Case: If you want to implement a complex conditional construction then you can use MySQL case statement. It performs the work as programming type.

MySQL Case

MySQL Case

     

This example illustrates how to use case statement in MySQL database.

MySQL Case: If you want to implement a complex conditional construction then you can use MySQL case statement. It performs the work as programming type.  The CASE statement  is used with two other keywords "WHEN" and "THEN". If the column data is matched with the "WHEN" data then it takes the corresponding "THEN" data. If no data is matched then the "ELSE" data is taken.

 

 

 

 

Table: employeeDetails

To use the mysql case:

SELECT daysName, CASE daysName 
  WHEN "Sunday" THEN "Holiday" 
  WHEN "Monday" THEN "Working Day" 
  WHEN "Tuesday" THEN "Working Day" 
  WHEN "Wednesday" THEN "Working Day" 
  WHEN "Thrusday" THEN "Working Day" 
  WHEN "Friday" THEN "Working Day" 
  WHEN "Saturday" THEN "Holiday" 
   ELSE "Illegal Argument" 
END AS "Status" 
from employeeDetails;

Output: