if else loop only iterating once I've discovered that my company's ETL proccess has a major bug in it around a process that checks if the ID in the staging database has already been used in the real database. In theory this processes should iterate through until it find an ID that has not been used, however on study it doesn't do that, only iterating once before stopping.

BEGIN
-- there is only ever 1 row in staging.
declare id1 char(12) default (select id from stg.extraction);

loop_label: Loop

if id1 not in (select id from main.extraction) Then
   leave loop_label;

end if;
   set id1=id1+1;
   leave loop_label;
 End Loop;

update stg.extraction
set id=id1;


END


I've tried several possible solutions but none of them seem to change things. I think I need to convert it to a while loop but I'm not sure.
Don't do it in a loop.  Do it in a single multi-table UPDATE and/or INSERT ... SELECT ... LEFT JOIN ... IS NULL.

More details:  http://mysql.rjweb.org/doc.php/staging_table#normalization