Report: Individuals (not: families!) with number of associated children

From TNG_Wiki
Jump to navigation Jump to search

Description: Individuals (not: families!) with number of associated children


Copy and paste the text between the lines into the reports section below "OR Leave Display, Criteria and Sort fields blank and enter direct SQL SELECT statement here:" and give it the title you think is appropriate


SELECT COUNT(*) AS Number_of_children, f.familyID, h.personID, h.lastname AS Last_name, h.firstname 
AS First_name, h.birthdate, h.deathdate, f.living, f.gedcom FROM tng_children AS c 
LEFT JOIN tng_families AS f ON c.familyID=f.familyID LEFT JOIN tng_people AS h ON f.husband=h.personID 
WHERE h.personID<>"" GROUP BY h.personID UNION SELECT COUNT(*) 
AS Number_of_children, f.familyID, w.personID, w.lastname 
AS Last_name, w.firstname AS First_name, w.birthdate, w.deathdate, f.living, f.gedcom 
FROM tng_children AS c 
LEFT JOIN tng_families AS f ON c.familyID=f.familyID 
LEFT JOIN tng_people AS w ON f.wife=w.personID WHERE w.personID<>"" 
GROUP BY w.personID ORDER BY Number_of_children DESC, Last_name, First_name, familyID