+1  A: 

From the incomplete information you provide, it looks like you should keep a Movements table:

Date/Time           Group      Action    Person    // The Universe

17/7/2009 10:01:00  Group A    Enter     John      // {A: John}
17/7/2009 10:02:00  Group A    Enter     Sally     // {A: John, Sally}
17/7/2009 11:22:23  Group B    Enter     Pete      // {A: John, Sally}, {B: Pete}
17/7/2009 11:34:45  Group A    Exit      John      // {A: Sally}, {B: Pete}

Note that the universe can be calculated just from the movements table. (Of course as the table grows this calculation becomes more costly, but I'm just making a basic suggestion.)

Daniel Daranas
Thanks for your answer. I added some more information to explain my implementation.
Nelson Reis
+1  A: 

It's not clear to me how you know that group 2 is the "same" group as group 1 - or is that information not important? Here is another solution, assuming groups continue to exist even when new members are added (which seems reasonable!)

create table groups (groupId integer primary key);
create table persons (personId integer primary key)
create table group_member (groupId references groups,
                           personId references persons,
                           startDate date,
                           endDate date);

Adding John:

insert into group_members (groupId, personId, startDate)
values (1, 1, '1/7/2009 11:00:00');

Removing John:

update group_members 
set endDate = '31/7/2009 12:24:00'
where groupId = 1 and personId = 1;

So by the end of your example you have:

PERSON:
PersonId   Name
 1         John
 2         Sally
 3         Pete

GROUP
groupId
1

GROUP_MEMBERS:
groupId personId startDate          endDate
1       1        1/7/2009 11:00:00  31/7/2009 12:24:00
1       2        31/7/2009 11:35:00
1       3        31/7/2009 12:10:00

To find out the membership of group 1 at some given date and time:

select personId
from   group_members
where  groupId = 1
and    startDate <= :given_datetime
and    (endDate is null or endDate >= :given_datetime);
Tony Andrews
To know which group is the one I want, I save the current group Id to another location, so before creating the new group, I check what's the current and the replace it. Thanks for your answer.
Nelson Reis