Map integer to text string in mysql
Posted by navaneeth on Mar 18, 2014 in MySQL, Php | No comments yet
We can use the functions CASE .. WHEN ...
to map integer to text string in mysql
The example query is as shown below
SELECT *, CASE type WHEN 1 THEN 'Enabled' WHEN 2 THEN 'Disabled' END as status FROM users
You can also use the ELSE clause to specify a default,
e.g.
CASE type WHEN 1 THEN 'Enabled' WHEN 2 THEN 'Disabled' ELSE 'Pending' END.
Leave a Reply