Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Many-to-many relationships in databases

by terce (Friar)
on Oct 28, 2005 at 08:19 UTC ( [id://503587]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Many-to-many relationships in databases
in thread Many-to-many relationships in databases : SOLVED

I don't think that's true, unless different SQL engines implement IN differently.
On all the engines I've used, IN is equivalent to a list of OR statements.
  • Comment on Re^3: Many-to-many relationships in databases

Replies are listed 'Best First'.
Re^4: Many-to-many relationships in databases
by Corion (Patriarch) on Oct 28, 2005 at 08:25 UTC

    How does that contradict my statement? The BookAuthors table seems to contain one entry for each pair (book, author), so (in a contrived example) it could look like the following:

    book author -------------------- 1 Jones 1 Miller 2 Jones 2 Smith 3 Smith 4 Jones

    The statement will return every book id for the given query of author IN ('Jones', 'Smith'), because, as you say, IN is more or less equivalent to a series of OR statements (I'm not sure about differences regarding NULL values).

      Perhaps I've misunderstood the OP, or your reply, but I don't understand why you say that using IN is only 'close' to correct - I don't see why it won't provide the results that the OP is after, for any number of authors.

        Quoting from the original post:

        Now in my application I want to include a search function which will find me the book(s) written by more than one author: "Give me the list of books written by Jones AND Smith". 'Jones' and 'Smith' being co-authors for these books as it were.

        Using IN on my example table will return lots of books that were not written by both, 'Smith' and 'Jones'. It will return all books co-authored by the two, but it will also return books written by only one of them.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-18 00:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found