http://www.perlmonks.org?node_id=992760

Freezer has asked for the wisdom of the Perl Monks concerning the following question:

The SQL below makes sense. However it is extremely slow. Am I right in thinking that a join (MySQL) could be used and that the code could dispense with the embedded Perl?
my $sql_count_A_Ref_vs_Comp = " SELECT '".$Reference."', '".$Comparitor."', A.entity_name FROM e_ann +otation_090812.annotation A WHERE A.user IN ( SELECT T.Line FROM e_annotation_090812.Temp_table T ) AND A.entity_name IN ( SELECT B.entity_name from e_annotation_090812.annotation B WHERE B.user IN ( SELECT U.Line FROM e_annotation_090812.Temp_table U ) AND B.entity_name LIKE '_%' AND B.evidence_code NOT LIKE +'%_________8__' AND B.centre LIKE '".$Reference."' ) AND A.entity_name LIKE '_%' AND A.evidence_code NOT LIKE '%______ +___8__' AND A.centre LIKE '".$Comparitor."' ";