I have a cross reference table that looks like this:
id document_id subject_id 1 8 21 2 5 17 3 5 76 4 7
select document_id from table1 where subject_id in (17, 76) group by document_id having count(distinct subject_id) = 2