@QuAzI , you can still do this as follows.
If specific values are passed to the request instead of paramId and paramParent
INSERT INTO a SELECT paramId, paramParent FROM a WHERE a.id = paramParent
If the intended parent is not found (there is no such id, which is equal to paramParent), then no changes will occur.
UPD:
Again, if it is possible to implement an algorithm using a stored procedure, then it is possible in the body of the procedure to check the presence of records by condition using SELECT EXISTS:
DELIMITER $ CREATE PROCEDURE myProc(id int, parent int) BEGIN IF (SELECT EXISTS(SELECT * FROM table1 WHERE table1.id = parent)) THEN INSERT INTO table1 VALUES(id, parent); END IF; END $
If necessary, it remains only to fasten a check for equality of id and parent and a check for the existence of id.
Another question - the speed I did not measure.