How to find parent's youngest child's name

Solution 1:

You can use ROW_NUMBER() function to number records.

This numbering is based on motherId,fatherId which is sorted by age column.

After that, you can extract the numbers 1 of each family.

Use this:

select id,motherId,fatherId,name,age from 
    (select *
            ,DENSE_RANK() over (partition by motherId,fatherId order by age asc  ) as rn
            from people where (motherId is not null and fatherId is not null  ))u
    where u.rn=1

Result:

id  motherId    fatherId    name    age
4   2           1           Seth    20