I have a table with different columns like so
CREATE TABLE survey(
id int(11) not null auto_increment,
what_is_your_name VARCHAR(255),
how_old_are_you varchar(20),
your_occupation varchar(255)
...
...
...
)
I need to build an output from the results of the survey table but I only need to concat the values if the column is not null.
So I want the final string to look like this if all the values are provided NAME IS: [what_is_your_name] AGE: [how_old_are_you] OCCUPATION: [your_occupation]
if only 2 values are provided but the [what_is_your_name] is null then the output should be like this NAME IS: [what_is_your_name] OCCUPATION: [your_occupation]
However, I only want to concat the value is the values are not null. Please note that the table above has a lot more question but I have only posted some of the table to explain the problem.
How can I do that in MySQL?
Thanks
CONCAT()andIFNULL()/COALESCE()/IF()functions