How about doing it with two tables? One table to store the member information, then a second table to store their favorites. For example:
create table member(
id number,
surname varchar2(30),
givenname varchar2(30),
emailaddr varchar2(40),
...etc...);
create table favorites(
member_id number,
favorite_type varchar2(10),
favorite_is varchar2(40));
The to find out everyone who likes cats or has a favorite color of blue or black, you would do:
select *
from member, favorites
where id = member_id
and ((favorite_type = 'COLOR' and favorite_is = 'BLUE')
or (favorite_type = 'COLOR' and favorite_is = 'BLACK')
or (favorite_type = 'ANIMAL' and favorite_is = 'CAT'));
or equivalently:
select
from member, favorites
where id = member_id
and favorite_type = 'COLOR'
and favorite_is = 'BLUE'
union
select
from member, favorites
where id = member_id
and favorite_type = 'COLOR'
and favorite_is = 'BLACK'
union
select *
from member, favorites
where id = member_id
and favorite_type = 'ANIMAL'
and favorite_is = 'CAT';
With the proper indexes on member(id) and favorites(member_id, favorite_type) retrieval would be fast even for large numbers of members with lots of favorites and lots of search criteria. To do 'A and B' instead of 'A or B' would just be changing the 'or'/'union' structuring, but still would be extremely efficient.
Of course to further normalize you would use a foreign key in place of favorite_type.
-- Michael
Darkstreak Computing & Innovations
www.darkstreak.com