![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm writing some code to suport a contact database, where a contact can be either a person or a group. Groups can contain people directly and can also contain other groups. The (simplified) table structure looks like this: PERSON ------ person_id number primary key GROUP ----- group_id number primary key MEMBER_OF_GROUP --------------- person_id number primary key 1 (foreign key -> PERSON.person_id) group_id number primary key 2 (foreign key -> GROUP.group_id) GROUP_IN_GROUP -------------- subgroup_id number primary key 1 (foreign key -> GROUP.group_id) supergroup_id number primary key 2 (foreign key -> GROUP.group_id) I want to write a single query that will tell me if a person is a member of a given group, whether as a direct member via the MEMBER_OF_GROUP table or as an indirect member of a child group via the GROUP_IN_GROUP table. Anyone have suggestions? -- John Gordon A is for Amy, who fell down the stairs gordon (AT) panix (DOT) com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" |
#3
| |||
| |||
|
|
I'm writing some code to suport a contact database, where a contact can be either a person or a group. Groups can contain people directly and can also contain other groups. The (simplified) table structure looks like this: PERSON ------ person_id number primary key GROUP ----- group_id number primary key MEMBER_OF_GROUP --------------- person_id number primary key 1 (foreign key -> PERSON.person_id) group_id number primary key 2 (foreign key -> GROUP.group_id) GROUP_IN_GROUP -------------- subgroup_id number primary key 1 (foreign key -> GROUP.group_id) supergroup_id number primary key 2 (foreign key -> GROUP.group_id) I want to write a single query that will tell me if a person is a member of a given group, whether as a direct member via the MEMBER_OF_GROUP table or as an indirect member of a child group via the GROUP_IN_GROUP table. Anyone have suggestions? -- John Gordon A is for Amy, who fell down the stairs gordon (AT) panix (DOT) com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" |
#4
| |||
| |||
|
|
I'm writing some code to suport a contact database, where a contact can be either a person or a group. Groups can contain people directly and can also contain other groups. The (simplified) table structure looks like this: PERSON ------ person_id number primary key GROUP ----- group_id number primary key MEMBER_OF_GROUP --------------- person_id number primary key 1 (foreign key -> PERSON.person_id) group_id number primary key 2 (foreign key -> GROUP.group_id) GROUP_IN_GROUP -------------- subgroup_id number primary key 1 (foreign key -> GROUP.group_id) supergroup_id number primary key 2 (foreign key -> GROUP.group_id) I want to write a single query that will tell me if a person is a member of a given group, whether as a direct member via the MEMBER_OF_GROUP table or as an indirect member of a child group via the GROUP_IN_GROUP table. Anyone have suggestions? -- John Gordon A is for Amy, who fell down the stairs gordon (AT) panix (DOT) com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" |
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Take a look at the nested set model. With nested sets, you'll be able to query for indirect children without coding up a recursive query. |
#9
| |||
| |||
|
|
Take a look at the nested set model. With nested sets, you'll be able to query for indirect children without coding up a recursive query. |
#10
| |||
| |||
|
|
Take a look at the nested set model. With nested sets, you'll be able to query for indirect children without coding up a recursive query. |
![]() |
| Thread Tools | |
| Display Modes | |
| |