Hello,

Not specific to sqlite, but a rather generic SQL question...

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
);

insert into document_token( 1, 11 );
insert into document_token( 1, 12 );

insert into document_token( 2, 11 );
insert into document_token( 2, 12 );

insert into document_token( 3, 11 );

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)?

Simply joining the two tables will result in all the document_id being  
returned:

select  distinct
        document_id
from    stage
join    document_token on document_token.token_id = stage.id

Thoughts?

Thanks in advance.

Kind regards,

--
PA.
http://alt.textdrive.com/nanoki/













_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to