with t (educationeventid, xml_part, iter) as ( select cast(educationeventid as varchar(255)) , substr(substr(xml,641), locate(' 0 union all select t.educationeventid, rtrim(substr(xml_part, locate(' 0 and iter < 20 ), tuples (t1, t2) as ( select educationeventid, rtrim(substr(xml_part, locate('"', xml_part)+1, locate('"/>', xml_part) - (locate('"', xml_part)+1))) from t where iter > 1 ) select e1.educationeventid, e2.educationeventid from tuples x, hubble.educationevent e1, hubble.educationevent e2 where varchar(x.t1) = e1.educationeventid and varchar(x.t2) = e2.educationeventid and e1.xml LIKE '%event/1.1%' and e2.xml like '%event/1.0%' ;