Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE t5 (
- col1 VARCHAR(36) NOT NULL PRIMARY KEY,
- col2 int(11) DEFAULT NULL,
- col3 int(11) DEFAULT NULL,
- UNIQUE (col2)
- );
- insert into t5(col1, col2, col3) values
- ('872c18ba-35ae-11e9-91a5-88d7f65253d0', 1, 1),
- ('823c3d3a-35ae-11e9-91a5-88d7f65253d0', 2, 2);
- insert into t5(col1, col2, col3) values
- ('872c18ba-35ae-11e9-91a5-88d7f65253d0', 2, 888),
- ('823c3d3a-35ae-11e9-91a5-88d7f65253d0', NULL, 999),
- on duplicate key update
- col2=if(values(col2) IS NULL, col2, values(col2)),
- col3=if(values(col3) IS NULL, col3, values(col3));
- update t5 set
- col2=(case col1 when '872c18ba-35ae-11e9-91a5-88d7f65253d0' then 2 END)
- col3=(case col1 when '872c18ba-35ae-11e9-91a5-88d7f65253d0' then 888 when '823c3d3a-35ae-11e9-91a5-88d7f65253d0' then 999 END)
- where col1 in ('872c18ba-35ae-11e9-91a5-88d7f65253d0', '823c3d3a-35ae-11e9-91a5-88d7f65253d0');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement