good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Many-to-many relationships in databasesby Corion (Patriarch) |
on Oct 28, 2005 at 06:30 UTC ( [id://503570]=note: print w/replies, xml ) | Need Help?? |
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:
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:
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 :-)
In Section
Seekers of Perl Wisdom
|
|