I have a table items
which has a field priority
. Half of the elements in field priority have a unique value ranging from 1
to x
. I want the elements where field priority
is null to have incremental values of x+1
to y
.
I have tried
UPDATE items
SET priority = IFNULL(priority, 0)
but that is not what I want. I want non null fields to stay as is, which I achieved with following:
SET priority = IFNULL(priority, 0)
and null fields to start being incremented from value, which I get with following:
SELECT MAX(priority)
FROM items;
So the only thing that comes to mind is something close to
UPDATE items
SET priority =
IFNULL(priority, 0) + (SELECT MAX(priority)
FROM items)
WHERE priority IS NULL
However I am not too sure how I would go about doing so. Any hints or tips?