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
-
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.