I have this table:
Now if I count rows in column id_racuna that are not NULL using: 
SELECT COUNT (id_racuna) FROM racuni WHERE id_racuna IS NOT NULL;
I get:
So if I use this value in an update like this:
UPDATE racuni AS r1 JOIN racuni AS r2 ON r1.id_interesa = r2.id_interesa
SET r1.id_racuna = (SELECT COUNT (r2.id_racuna) FROM r2 WHERE r2.id_racuna IS NOT NULL) +1,
    r1.poslano = curdate()
WHERE r1.id_interesa = 8;
I would expect to get:
but I get an error:
Table r2 doesn't exist!
I tried to trick MySQL using JOIN to think that r1 and r2 are two different tables, but it doesn't work. I have seen this kind of trick here where it worked... What am I missing?
UPDATE:
I need to use JOIN because if I wrote just: 
UPDATE racuni
SET id_racuna = (SELECT COUNT (id_racuna) FROM racuni WHERE id_racuna IS NOT NULL) +1,
    poslano = curdate()
WHERE id_interesa = 8;
I would get error:
Table 'racuni' is specified twice, both as a target for 'UPDATE' and as a separate source for data



 
    