CREATE TABLE `users` (
`id` int(11) AUTO_INCREMENT,
`academicdegree` varchar(255),
`name` varchar(255),
`firstname` varchar(255),
`sex` enum('m','f')
)
SELECT TRIM(CONCAT_WS(" ", firstname, name)) AS fullname FROM users
Is there a way to add a useful salutation (Mr. or Mrs.) according to the ENUM value stored in the field “sex” in just one query?
Bonus track:
I only can replace this part of the query: TRIM(CONCAT_WS(" ", firstname, name)) and ; is not allowed.
This will work just fine:
You could use a
CASEstatement, however if you’ve only got two options anIF()statement makes more sense.