I have a table racuni
which has a column id_racuna
that only has NULL
values in it.
This is the table creation query:
CREATE TABLE racuni
(
id_interesa INT UNSIGNED NOT NULL AUTO_INCREMENT,
id_racuna INT UNSIGNED NULL,
PRIMARY KEY (id_interesa)
) ENGINE=InnoDB;
As you can see, AUTO_INCREMENT
has already been used on the primary key so I can't use it anymore to increment id_racuna
. So I tried to use this query:
UPDATE racuni
SET id_racuna = CASE
WHEN (SELECT id_racuna FROM racuni ORDER BY id_racuna DESC LIMIT 1) IS NULL THEN 1
ELSE id_racuna +1
END
WHERE id_interesa IN (2);
But I get an error:
I have seen people using aliases to solve this problem but they usualy deal with INSERT
statements, so I am kind of lost here. How could I use aliases in my case? In the book from Ben Forta I read that aliases are provided using AS
keyword, but people on this forum don't use it...