Petite Abeille <[EMAIL PROTECTED]> wrote: > Given a set of ids, what would be the proper way to find the records > containing all those ids? > > Specifically, given a 'document_token' table containing a document_id > mapping to multiple token_id, how would one find the document_id which > contains all the given token_id? > > E.g.: > > create table if not exists document_token > ( > document_id integer not null, > token_id integer not null > ); > > create temporary table if not exists stage > ( > id integer not null, > ); > > insert into stage( 11 ); > insert into stage( 12 ); > > Given an input of 11 and 12 as token_id in the 'stage' table, what > would be the proper query to retrieve document_id 1 and 2 (but not 3 > as it only contains token_id 11)?
select document_id from document_token join stage on (token_id = id) group by document_id having count(*) = (select count(*) from stage); Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users