Add a SET list value to Mysql

Asked

Viewed 53 times

0

I want to add values in a list (values separated by "," which will then be used the "split" function) in mysql, I am using this code: UPDATE clans SET Admins = concat(Admins, ',', 'NomeDoJogador') WHERE Name = 'NomeDoClan', but when I add a value, and the list is empty, "," is sent before the value, and this was only to happen if there was more than one value in the list. Code used to remove a player from the "list" if necessary: UPDATE clans SET Admins = REPLACE(REPLACE(Admins, ',NomeDoJogador', ''), 'NomeDoJogador', '') WHERE Name = '" + _clanName + "'

1 answer

0

Instead of using CONCAT use CONCAT_WS:

UPDATE clans SET Admins = CONCAT_WS(',', Admins, 'NomeDoJogador') WHERE Name = 'NomeDoClan'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.