I want to update my raw with if-else condition. Here is my sql code;
update posts
set like =
if(json_contains(like,2,'$'),
json_remove(like,replace(json_search(like,'one',2),'"','')),
json_array_append(like,'$',2)
)
where id = 3
My table;
| id | like |
|---|---|
| 2 | [] |
| 3 | [2] |
After this sql code id= 3 should be like id = 2.
To sum up,: if json contain, remove from json; if json not contain, push data to array
SHOW CREATE TABLE. Maybe this the Answer:AUTO_INCREMENTvalues do not change without explicit action.