Mysql case else

broken image

Here we check the condition and if it is True then the respective statement is executed. In this case we don't specify any value or data to be matched, instead we work on testing some conditions and if it is True then respective statement is to be executed. We can display based on the floor wise or location wise by using order by query SELECT `id`, `name`, `class`, `mark`, `gender` ,įROM `student` ORDER BY location Second Type (Matching condition with CASE statement) There are more records, here it is limited to 10 only.

broken image

SELECT `id`, `name`, `class`, `mark`, `gender` , Using CASE in our query statement is here. Our list should display student details with class and location of the class.

broken image

We have allotted rooms for the classes at different floors in a school. We will use our student table for this example. If any WHEN statement is matched then rest WHEN statements are not checked and matched statement is returned. If nothing is matched then statement under X_statement is executed.

broken image

If it is not matched than next WHEN value C_value is checked. If A_value equals to B_value then B_statement is executed. Here A_value is matched with different values given under WHEN. MySQL case – when –then to match against value or condition with GROUP by and BETWEEN query

broken image