SELECT t1.id,t1.id1FROM tbltests t1WHERE NOT EXISTS(SELECT * FROM tbltests t2 WHERE t2.id = t1.id1 AND t2.id1 = t1.id AND t2.id < t2.id1)