I have a table tbl_scripts
that goes like this:
allowed_group_ids
+-----------------+
12343,12343,21342
And I need to remove from this string a group id, for example 12343. Setting delete_group_id
to 12343
, the below query seems to work correctly:
UPDATE tbl_scripts
SET allowed_group_ids =
REPLACE(
REPLACE(allowed_group_ids, '$delete_group_id,', ''),
',$delete_group_id', '')
WHERE
system_id = {$_SESSION['system_id']}
But if the column only has a single value, it fails:
allowed_group_ids
+-----------------+
12343 <-----I'm not able to replace this with blank
I know I should normalize the table, but at the moment I can't change my database structure, so I'm trying to make it work this way. How can I make my query work with single values?