Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Many-to-many relationships in databases

by davorg (Chancellor)
on Oct 28, 2005 at 08:51 UTC ( [id://503596]=note: print w/replies, xml ) Need Help??


in reply to Many-to-many relationships in databases : SOLVED

This is really off-topic for this site, but let's have a go anyway.

You need to join the BookAuthor table with itself. I'm old-skool so I do joins in the WHERE clause, but there's probably a simpler way to do it using an explicit JOIN clause.

select a.book from BookAuthor a, BookAuthor b where a.author = 'Smith' and b.author = 'Jones' and a.book = b.book;

Update: The JOIN syntax looks like this:

select a.book from BookAuthor a inner join BookAuthor b on a.book = b.book where a.author = 'Smith' and b.author = 'Jones';

You should be able to omit the "INNER", but I was testing on a rather old version of MySQL which didn't support the abbreviated syntax.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://503596]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2024-03-28 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found