INSERT INTO vocabulary_relations
(vocabulary_id, related_id)
SELECT v1.id, v2.id
FROM RelatedItems ri
INNER JOIN vocabulary v1
ON ri.col1 = v1.name
INNER JOIN vocabulary v2
ON ri.col2 = v2.name