As I'm working my way through Celkos "SQL for Smarties", he points out an interesting way to map such boolean queries by using GROUP BY and HAVING:
-- find all book ids coauthored by Smith and Jones:
-- (let's assume that the author_name is unique)
select book_id, count(*) from authors
where
author_name = 'Smith'
or author_name = 'Jones'
group by book_id
having count(*) = 2
Whether the performance of this is better or worse than selecting all books by one and all books by the other and scanning the lists in Perl, or worse than dynamically creating the self joins needs to be benchmarked. Another way to make this slightly less dynamic could be to use the IN predicate:
-- find all book ids coauthored by Smith and Jones:
-- (let's assume that the author_name is unique)
select book_id, count(*) from authors
where
author_name in ('Smith', 'Jones')
group by book_id
having count(*) = 2
To make it completely static, you could insert the authors into a (session-local) temporary table and cross-join that table.
Update: Oops - this approach will also return books co-authored by 'Smith', 'Jones' and 'Miller'. Depending on whether that's what you want or not, you will need to use a subselect to make sure you get all of the authors. But I'm not sure if I can come up with the correct subselect at the moment :-)