Algorithm for the UNION