Lets start at the begining. What are those *asterixes* doing around answer? You might just be able to get away with :-
SELECT * FROM Grade_Theory WHERE 'The funcdamental particle is called +a quark, Bob!' LIKE '%'||Answer||'%'
But I have never needed to use this reverse syntax. To be perfectly honest with you this looks less like a perl question and more like an advanced database design question.

Ideally you need to understand the importance of the key words in the answers.

So let us try and build up a dynamic query that tries to find important words. Your initial SQL starts off :-

SELECT * FROM Grade_Theory
Although this sounds ok it can create massive performace issues in the future when some adds many large columns to the table. Always specify exactly what you are after.
SELECT RowID, Question,Answer FROM Grade_Theory
Now comes the tricky part finding the matching answer. Now we do not know exactly how many words are relivent so we need to try and find a best match. Perl can help by generating the where clause.
my @words = split /\W+/, 'The funcdamental particle is called a quark, + Bob!'; my @parts = (); for (@words) { push @parts, "Answer like '%$_%'"; } my $where_clause = join (" or\n",@parts); my $sql = "SELECT RowID, Question,Answer FROM Grade_Theory WHERE $where_clause"; print "$sql\n";
This will result in the following type of query.
SELECT RowID, Question,Answer FROM Grade_Theory WHERE Answer like '%The%' or Answer like '%funcdamental%' or Answer like '%particle%' or Answer like '%is%' or Answer like '%called%' or Answer like '%quark%' or Answer like '%Bob%'
You can improved this by removing short/irrelvent words from the word list.
my @words = split /\W+/, 'The funcdamental particle is called a quark, + Bob!'; my @long_words=(); for (@words) { push @long_words, $1 if (/^(\w{3,})$/); } my @parts = (); for (@long_words) { push @parts, "Answer like '%$_%'"; } my $where_clause = join (" or\n",@parts); my $sql = "SELECT RowID, Question,Answer FROM Grade_Theory WHERE $where_clause"; print "$sql\n";
This will result in the following resulting query.
SELECT RowID, Question,Answer FROM Grade_Theory WHERE Answer like '%The%' or Answer like '%funcdamental%' or Answer like '%particle%' or Answer like '%called%' or Answer like '%quark%' or Answer like '%Bob%'
If you want to go any further you really need a completely different design of database. If you have a table that contains words and a many to many relationship between that and your question table you could then do a far more interesting query. But this is PERL monks so I will lay of the database theory.

Hope it helps
UnderMine


In reply to Re: Wildcards, SQL and Perl by UnderMine
in thread Wildcards, SQL and Perl by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.