use `akura`;


CREATE TEMPORARY TABLE TEMP_STUDENT_PARENT (STUDENT_PARENT_ID INT(11));
INSERT INTO TEMP_STUDENT_PARENT (
 SELECT SP2.STUDENT_PARENT_ID  FROM STUDENT_PARENT AS SP2 WHERE 
		CONCAT(SP2.STUDENT_ID,SP2.RELATIONSHIP) IN (SELECT CONCAT(SP1.STUDENT_ID,SP1.RELATIONSHIP) FROM STUDENT_PARENT AS SP1 GROUP BY SP1.STUDENT_ID,SP1.RELATIONSHIP HAVING COUNT(*)>1)
		AND SP2.STUDENT_PARENT_ID NOT IN ( SELECT MAX(STUDENT_PARENT_ID) FROM STUDENT_PARENT GROUP BY STUDENT_ID,RELATIONSHIP ) );
DELETE FROM STUDENT_PARENT WHERE STUDENT_PARENT_ID IN (SELECT * FROM TEMP_STUDENT_PARENT);
DROP TABLE TEMP_STUDENT_PARENT;
