Add parent_id dynamically based on another field
CREATE TEMP TABLE v2
    SELECT * 
    FROM version;

UPDATE version v1 
SET parent_id = (
    SELECT id 
    FROM v2 
    WHERE v2.order &lt; v1.order 
    ORDER BY v2.order DESC LIMIT 1
);