0

I'm trying to accomplish something like this? How could I be able to do something like this in a query?

The caveat is that I want to change the old pk so for example if it was 888 I want to change it to 999 and still only have 1 row in the table.

SET @toReplaceInto := (SELECT `pk` FROM `my_table` ORDER BY `pk` DESC LIMIT 1);
IF @toReplaceInto = NULL THEN
INSERT INTO `my_table` 
  (`pk`,`number`) VALUES (999,2);
ELSE
REPLACE INTO `my_table` 
  (`pk`,`number`) VALUES (999,2,2,3,4,5,6,7) WHERE `pk` = @toReplaceInto;
END IF;
``
wayfarer
  • 11
  • 5

0 Answers0