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

Just my 2 cents here. The IN is CaSe sensitive, so a search for Smith will only return Smith, not smith (atleast not in the MySQL version I have here). Sounds trivial, however, if your allowing the user to enter a name, then its no longer trivial. On the other hand LIKE returns Smith, smith, sMiTh and any other variants, however, each queried name must be entered indivuially.... (The good with the bad I guess).
SELECT book FROM BooksAuthors AS B1 JOIN BooksAuthors AS B2 WHERE B1.Author LIKE '%Jones%' AND B2.Authors LIKE '%Smith%' AND B1.Book = B2.Book
To note here, the % sign is a wild card. Thus, if searching for John using John%, would also return items like Johny. Use only if you think it may be necessary.

You could make a for loop to create a query variable that, essentually does something like:
Assign select query up to WHERE
Loop through user input adding B1.Author LIKE '$input' AND B2.Authors LIKE '$input' (don't forget an AND or OR claus between each pass)
Add the AND B1.Book = B2.Book to the end of the variable, then run the query, process the output.

Replies are listed 'Best First'.
Re^2: Many-to-many relationships in databases
by davorg (Chancellor) on Oct 28, 2005 at 12:28 UTC

    Just convert everything to upper case. Far more efficient than using LIKE unnecessarily.

    SELECT book FROM BooksAuthors AS B1 JOIN BooksAuthors AS B2 ON B1.Book = B2.Book WHERE UPPER(B1.Author) = 'JONES' AND UPPER(B2.Author) = 'SMITH'
    --
    <http://dave.org.uk>

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