> I have a table of people. Some of the people in this table are
> related. You can find out who is related by comparing a familyID
> number. I have a query to select a certain group of people from the
> table and I want to also select anyone who is related to them, even
> though those who are related will not match the other criteria. So my
> table is something like this....
> . . .
> I have a query like this....
> Select * from people where BirthDate < 1987 and Birthday > 1950 and
> address = "xyz"
> I need to change it so it includes everyone that has the same Family ID
> as each person that query will return and group it by Family ID
if you are using a new enough version (4.1 or newer) you can use a subquery.
If I understand your intention correctly, the following statement should do
what you need:
select familyid, count(PID) from people where FamilyID = (select FamilyID
from people where BirthDate < 1987 and Birthday > 1950 and address = "xyz")
group by FamilyId
If your version does not support sub-queries, have at look at