Mysql insert on the first empty column on duplicate key update -
i'm trying set query insert data on first empty column or, if key value exists, update on first empty column
"insert table (myid,tr1) values ('12345', '$data') on duplicate key update tr1 = case when tr1 = '' else tr1 end, tr2 = case when tr2 = '' else tr2 end, tr3 = case when tr3 = '' else tr3 end = $data"
where myid unique key, in other words:
-------------------------- | myid | tr1 | tr2 | tr3 | -------------------------- | 1233 | data| | | -------------------------- | | | | | --------------------------
when id matchs, updates $data in next empty column, in case myid=1233 column tr2. when myid not exist insert myid , $data on tr1. query getting syntax error appreciate help!
maybe problem in case clause. try example.
i made changes on query, should work. example
insert `table` (myid,tr1) values ('12345', '111') on duplicate key update tr3 = case when tr2 != '' , tr3 = '' '111' else tr3 end, tr2 = case when tr1 != '' , tr2 = '' '111' else tr2 end, tr1 = case when tr1 = '' '111' else tr1 end;
Comments
Post a Comment