SQLTeam.com | Weblogs | Forums

Help with SQL Query

I have a small Genealogy Website that uses SQL
I have the following code to search one table for the following info:

SELECT id, lastname, firstname, birthdatetr, deathdatetr
FROM tng_people
WHERE (burialplace LIKE "%missouri%") AND (deathdatetr BETWEEN "1910-01-01" AND "1965-12-31")
ORDER BY lastname, firstname ASC

In another table "tng_media" column name "mediatype" I need to see if those selected in the above query have a "death Certificate" affiliated with them.

mediaID | mediatypeID | gedcom | form | path | description | placetaken | notes | owner | thumbpth | etc....
7574 | death |Cervenka1| JPG |Death Certificate - John Doe.jpg |Death Certificate - John Doe | | | | |

Please provide:

  • table definitions of both tables in the form of create statements
  • sample data from both tables in the form of insert statements
  • expected output from the sample data you provide

Here are screen shots of the tables involved:
As a new user I can only post one image each.
The others will be folllowing

This is what I have so far and it works, but I only need one instance per Individual.
This selects multiple rows for the same person

SELECT tng_people.personID, lastname, firstname, birthdatetr, deathdatetr, deathplace, eventID, tng_medialinks.personID
FROM tng_people, tng_medialinks
WHERE (tng_people.personID = tng_medialinks.personID) AND (tng_medialinks.eventID NOT LIKE 'deat') AND (burialplace LIKE "%missouri%") AND (deathdatetr BETWEEN "1910-01-01" AND "1965-12-31")
ORDER BY lastname, firstname ASC

Tyr this:

select p.personID
  from tng_people as p
       left outer join tng_medialinks as ml
                    on ml.personID=p.personID
                   and ml.eventID='DEAT'
 where p.deathdatetr>=cast('1910-01-01' as date)
   and p.deathdatetr< cast('1966-01-01' as date)
   and p.burialplace like "%missouri%"
 order by p.lastname