This could turn out to be the dumbest question ever.
I want to track groups and group members via SQL.
Let's say I have 3 groups and 6 people.
I could have a table such as:
Then if I wanted to have find which personIDs are in groupID 1, I would just do
select * from Table where GroupID=1
(Everyone knows that)
My problem is I have millions of rows added to this table and I would like it to do some sort of presorting about GroupID to make lookups as fast as possible. I'm thinking of a scenario where it would have nested tables, where each sub table would contain a groupID's members. (Illustrated below)
This way when I wanted to select each GroupMembers, the structure in SQL would already be nested and not as to expensive look up as would trolling through rows.
Does such a structure exist, in essence, a table that would pivot around the groupID ? Is indexing the table about groupID the best/only option?