Lecho <[EMAIL PROTECTED]> writes:
>I have a db with objects table, each of those objects may belong to groups
>of objects. The number of groups can be about 256 and an object
>belongs from one to many different groups at once.

Lecho,
     I threw together the following tables/data/queries that I believe
handle your setup:

create table objs (
        obj_id          int,
        obj_name        varchar(20)
);

create table grps (
        grp_id          int,
        grp_desc        varchar(20)
);

create table grp_map (
        obj_id          int,
        grp_id          int
);

insert into objs (obj_id, obj_name) values (1, 'Obj1');
insert into objs (obj_id, obj_name) values (2, 'Obj2');
insert into objs (obj_id, obj_name) values (3, 'Obj3');
insert into objs (obj_id, obj_name) values (4, 'Obj4');

insert into grps (grp_id, grp_desc) values (10, 'Grp10');
insert into grps (grp_id, grp_desc) values (20, 'Grp20');
insert into grps (grp_id, grp_desc) values (30, 'Grp30');

insert into grp_map (obj_id, grp_id) values (1, 10);
insert into grp_map (obj_id, grp_id) values (1, 30);

insert into grp_map (obj_id, grp_id) values (2, 20);
insert into grp_map (obj_id, grp_id) values (2, 30);

insert into grp_map (obj_id, grp_id) values (3, 10);
insert into grp_map (obj_id, grp_id) values (3, 20);
insert into grp_map (obj_id, grp_id) values (3, 30);

insert into grp_map (obj_id, grp_id) values (4, 30);

select distinct(obj_id) from grp_map
    where grp_id in (10, 20);

mysql> select distinct(obj_id) from grp_map
    ->     where grp_id in (10, 20)
    -> ;
+--------+
| obj_id |
+--------+
|      1 |
|      2 |
|      3 |
+--------+
3 rows in set (0.00 sec)

This will tell you all the objects that belong to groups 10 or 20

Brad Eacker ([EMAIL PROTECTED])



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to