L
Laurel
I have an unnormalized database that isn't mine - I can't re-structure it.
It contains the names and addresses of all the members of our congregation,
and I've been asked to generate a directory, with the address of each
household showing only once, and the names of the children falling under the
parents. It needs to be sorted by the last name of the HHD_Label row.
Previously, we simply listed them alphabetically, last name, first name, and
families with the same last name were all over the map (to mix a metaphor).
A "household" is all the people living at the same address. The thing that
has me the most stumped, is how to gather the households together in the
result set, but still sort by the last name of the HHD_LabelTag row.
I'm willing to add some columns of information to try to deal with this.
But I can't figure out the SQL. Can anyone help?
Desired output
<Household_Directory_Name> <address> <city> <state>
<zip> <phone> <e-mail>
<other household member (first_name, last_name>
<phone> <e-mail>
<other household member>
<phone> <e-mail>
<other household member>
<phone> <e-mail>
Here are the relevant database columns - one row per person
Household key (a number - the same for all members of a household)
HHD_LabelTag (set to yes for one member of the family - currently used to
mail to households using just the last name)
Househould_Directory_Name
Other_Household_Member (I think I need this so the spouse doesn't show up in
a list with the children.)
first_name
last_name
address
city
state
zip
phone 1
phone 2
e-mail
It contains the names and addresses of all the members of our congregation,
and I've been asked to generate a directory, with the address of each
household showing only once, and the names of the children falling under the
parents. It needs to be sorted by the last name of the HHD_Label row.
Previously, we simply listed them alphabetically, last name, first name, and
families with the same last name were all over the map (to mix a metaphor).
A "household" is all the people living at the same address. The thing that
has me the most stumped, is how to gather the households together in the
result set, but still sort by the last name of the HHD_LabelTag row.
I'm willing to add some columns of information to try to deal with this.
But I can't figure out the SQL. Can anyone help?
Desired output
<Household_Directory_Name> <address> <city> <state>
<zip> <phone> <e-mail>
<other household member (first_name, last_name>
<phone> <e-mail>
<other household member>
<phone> <e-mail>
<other household member>
<phone> <e-mail>
Here are the relevant database columns - one row per person
Household key (a number - the same for all members of a household)
HHD_LabelTag (set to yes for one member of the family - currently used to
mail to households using just the last name)
Househould_Directory_Name
Other_Household_Member (I think I need this so the spouse doesn't show up in
a list with the children.)
first_name
last_name
address
city
state
zip
phone 1
phone 2