rvdveen27 Posted May 27, 2015 Share Posted May 27, 2015 Hello all, Is it possible to change the database output? For example I have a selection which puts either 1, 2 or 3 into the database for an answer. Now I want to get that 1, 2 or 3 out of the database again but then I want it in the code to be changed for example to: 1 = yes 2 = no 3 = maybe Could anyone tell me how to do this? Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted May 27, 2015 Solution Share Posted May 27, 2015 SELECT CASE colname WHEN 1 THEN 'Yes' WHEN 2 THEN 'No' ELSE 'Maybe' END as Selection FROM tablename 1 Quote Link to comment Share on other sites More sharing options...
Barand Posted May 28, 2015 Share Posted May 28, 2015 (edited) Alternatively, you could use an ENUM type column CREATE TABLE `users` ( `id` int(5) NOT NULL AUTO_INCREMENT, `username` varchar(45) DEFAULT NULL, `status` enum('yes','no','maybe') NOT NULL DEFAULT 'no', PRIMARY KEY (`id`) ) ; INSERT INTO users (username,status) VALUES ('Peter', 1), ('Paul', 3), ('Mary', 2); Then when you select mysql> SELECT * FROM users; +----+----------+--------+ | id | username | status | +----+----------+--------+ | 1 | Peter | yes | | 2 | Paul | maybe | | 3 | Mary | no | +----+----------+--------+ Edited May 28, 2015 by Barand Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.