By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tab
AS
SELECT 1 AS ID, 'Paul' AS Name, NULL AS Father_id, NULL As Mother_id
UNION ALL SELECT 2 , 'Debbie' ,NULL,NULL
UNION ALL SELECT 3 , 'Jessie' ,NULL,NULL
UNION ALL SELECT 4 ,'Pam' , 1, 3
UNION ALL SELECT 5 ,'Sue' , 1 , 3
UNION ALL SELECT 6 ,'Trish' , 1 , 3
UNION ALL SELECT 7 ,'Sarah' , 1 , 2
UNION ALL SELECT 9 ,'John' , NULL,NULL
UNION ALL SELECT 10 ,'johnny' , 9, 4
UNION ALL SELECT 11 ,'Ben' , 9 , 4
Records: 10 Duplicates: 0 Warnings: 0
SELECT *
FROM tab
WHERE Id IN (
SELECT Father_Id
FROM tab
GROUP BY Father_Id
HAVING COUNT(DISTINCT Mother_id) > 1
UNION ALL
SELECT Mother_Id
FROM tab
GROUP BY Mother_Id
HAVING COUNT(DISTINCT Father_Id) > 1
)
ID | Name | Father_id | Mother_id |
---|---|---|---|
1 | Paul | null | null |