my $members = join("; ", @member); #### select * from celebrities where professions like '% 002 %' #### select * from celebrities where professions='002' -- The only item in the list or professions like '002 %' -- it might be first of several or professions like '% 002' -- it could be the last of several or professions like '% 002 %' -- or in the middle #### if 1 > (select count(*) from celebrities where (professions='002' or professions like '002 %' or professions like '% 002' or professions like '% 002 %') and cel_id=X ) then /* Celebrity isn't an actor, so add to the end */ update celebrities set professions = '002' || case when professions is null then '' else ' '||professions end where cel_id=X; end if; #### select * from celebrities where cel_id in ( select cel_id from celebrity_professions where prof_id='002' ) #### if 1 > (select count(*) from celebrity_professions where prof_id='002' and cel_id=X ) then insert into celebrity_professions (cel_id, prof_id) values (X, '002'); end if; #### delete celebrity_professions where cel_id=X and prof_id='002'; #### select * from celebrities where cel_id in ( select cel_id from celebrity_groups where group_id in ( select prof_id from celebrity_groups where cel_id=X ) )