select id,sub_id from tab a,tab b where a.subid=b.id order by id;