CASE in Mysql
CASE in Mysql:
This function used to select particular Case. If there was no matching result value, the result after ELSE is returned.The default return type of a CASE expression is the compatible aggregated type of all return values, but also depends on the context in which it is used. If used in a string context, the result is returned as a string. If used in a numeric context, then the result is returned as a decimal, real, or integer value.
Syntax :
CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN result …] [ELSE result] END
Example :
SELECT CASE ‘a’
WHEN ‘a’ THEN
(select count(*) from a_wordlist )
WHEN ‘b’ THEN
(select count(*) from b_wordlist )
ELSE ‘SELECT a or b’ END;
Output:
750 (a_wordlist count)
