Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: Many-to-many relationships in databases by Delusional
in thread Many-to-many relationships in databases : SOLVED by CountZero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found