Let's see if I can still do this:
my $ar_data = $dbh->selectall_arrayref(qq ( SELECT noot.Reference, aap.Comparitor, aap.entity_name FROM ( SELECT ? AS Comparitor, entity_name FROM e_annotation_090812.annotation AS A JOIN e_annotation_090812.Temp_table AS T ON A.user = T.Line WHERE IFNULL(A.entity_name, '') <> '' AND A.evidence_code NOT LIKE '%_________8__' AND A.centre = ? ) AS aap JOIN ( SELECT ? AS Reference, entity_name FROM e_annotation_090812.annotation AS B JOIN e_annotation_090812.Temp_table AS U ON B.user = U.Line WHERE IFNULL(B.entity_name, '') <> '' AND B.evidence_code NOT LIKE '%_________8__' AND B.centre = ? ) AS noot ON aap.entity_name = noot.entity_name ), { Slice => {} }, ".${Comparitor}.", ".${Comparitor}.", ".${Referenc +e}.", ".${Reference}.") or die("Error executing query: " . $dbh->errs +tr);
Note that this is untested :)
Feedback is appreciated

Edit: Could you provide a small portion of (dummy) testdata to work with, as well as the DDL (the result of SHOW CREATE TABLE e_annotation_090812.annotation) of both tables?
This is handy to find further optimizations (for example, if evidence_code is a numerical field, using LIKE is very bad as it needs to typecast and thus can't use an index if present).

Edit2: Changed centre LIKE ? to centre = ? which should be better unless you're using wildcards (_ or %) in $Reference or $Comparitor


In reply to Re: s/Perl/SQL/ ? by Neighbour
in thread s/Perl/SQL/ ? by Freezer

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.