Home > Net >  Removing an element in an MySQL's JSON array in a column
Removing an element in an MySQL's JSON array in a column

Time:08-24

I have a "table" named users with a column name "group_in" which stores an array like [1,2,3].

I am trying to remove an element with a value (eg. 1) for a specified row (eg id:1).

Before:

id| group_in  
1 | **[1,2,3]**  
2 | [1,3]

After:

id |  group_in  
1  |  **[2,3]**  
2  |  [1,3]

I have tried the following:-

Update users 
SET group_in = JSON_REMOVE(group_in,JSON_UNQUOTE(JSON_search(group_in, 'one', 1)))
where id = 1 

but I got back is

id |  group_in  
1  |  null           
2  |  [1,3] 

Screenshot of my table and query result for your reference.
Click Here To See Output Snapshots

  • Related