+ 1
How to skip single delimiter and 0 value?
there is a task where i need to select the "first name", "second name", "email", "phone number" and "rating" into a single column and delimit the value with comma. The problem is, not every value contain email or contain rating "0" How to skip single delimiter and 0 value? select concat_ws(", ", first name, second name, email, phone number, rating) as person How to continue it?
1 Resposta
+ 2
You can apply conditions with the if() statement in mysql and do a null check with ISNULL()
https://www.geeksforgeeks.org/mysql-if-function/
https://www.w3schools.com/sql/func_mysql_isnull.asp
I would just use concat instead of concat_ws and insert the commas between each field, and use the condition like this:
IF(ISNULL(email), '', CONCAT(',', email))