[IMPORTANT] This is an exercise from the book 'Learning SQL', so I cannot use any other method other than CASE-WHEN. I have a table as follows:
The question is as follows:
Rewrite the following query, which uses a simple case expression, so that the same results are
achieved using a searched case expression. Try to use as few when clauses as possible.
SELECT name,
CASE name
WHEN 'English' THEN 'latin1'
WHEN 'Italian' THEN 'latin1'
WHEN 'French' THEN 'latin1'
WHEN 'German' THEN 'latin1'
WHEN 'Japanese' THEN 'utf8'
WHEN 'Mandarin' THEN 'utf8'
ELSE 'Unknown'
END character_set
FROM language;
I tried the following:
SELECT name,
CASE name
WHEN language.name IN ('English','Italian','French','German')
THEN 'latin'
WHEN language.name IN ('Japanese','Mandarin')
THEN 'utf8'
ELSE 'Unknown'
END character_set
FROM language;
This is giving me a result that is exactly the opposite of what is mentioned in the conditions, for example it shows 'utf8' for 'English', and 'latin1' for 'Mandarin'. What am I doing wrong?