$sql = "SELECT action_id FROM transactions LEFT JOIN actions ON transactions.transaction_id = actions.transaction_id LEFT JOIN merchants ON merchant_id = idmerchants WHERE mdf_20 = 'a4bbf326102e3064a8d9e06558c4b5e2020ee353' OR mdf_20 LIKE '_a4bbf326102e3064a8d9e06558c4b5e2020ee353%' AND action_type IN ('capture','sale') AND ABS(amount) = ABS('$amnt') AND success = 1 AND processor_settlement_date IS NULL ORDER BY transaction_date;"; $sth = $dbh->prepare($sql); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n"; $sth->finish; $sql = "SELECT action_id,transaction_date FROM transactions LEFT JOIN actions ON transactions.transaction_id = actions.transaction_id LEFT JOIN merchants ON merchant_id = idmerchants WHERE mdf_20 = '1442a29888840b0b9505d34da6cd8897d153976d' AND action_type IN ('capture','sale') AND processor_settlement_date IS NULL UNION SELECT action_id,transaction_date FROM profitorius.actions WHERE transaction_id LIKE '1442a29888840b0b9505d34da6cd8897d153976d%' AND ABS(amount) = ABS('49.95') AND success = 1 AND action_type IN ('capture','sale') AND processor_settlement_date IS NULL ORDER BY transaction_date;"; $sth = $dbh->prepare($sql); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n"; $sth->finish; $sql = "SELECT action_id,transaction_date FROM transactions LEFT JOIN actions ON transactions.transaction_id = actions.transaction_id LEFT JOIN merchants ON merchant_id = idmerchants WHERE mdf_20 = 'a4bbf326102e3064a8d9e06558c4b5e2020ee353 ' AND action_type IN ('capture','sale') AND processor_settlement_date IS NULL UNION SELECT action_id,transaction_date FROM profitorius.actions WHERE transaction_id LIKE 'a4bbf326102e3064a8d9e06558c4b5e2020ee353 %' AND ABS(amount) = ABS('4.95') AND success = 1 AND action_type IN ('capture','sale') AND processor_settlement_date IS NULL ORDER BY transaction_date;"; $sth = $dbh->prepare($sql); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n"; $sth->finish; #### mysql> SELECT action_id,transaction_date -> FROM transactions LEFT JOIN actions -> ON transactions.transaction_id = actions.transaction_id -> LEFT JOIN merchants ON merchant_id = idmerchants -> WHERE mdf_20 = '1442a29888840b0b9505d34da6cd8897d153976d' -> AND action_type IN ('capture','sale') -> AND processor_settlement_date IS NULL -> UNION -> SELECT action_id,transaction_date FROM profitorius.actions -> WHERE transaction_id LIKE '1442a29888840b0b9505d34da6cd8897d153976d%' -> AND ABS(amount) = ABS('49.95') AND success = 1 -> AND action_type IN ('capture','sale') -> AND processor_settlement_date IS NULL -> ORDER BY transaction_date; +-----------+---------------------+ | action_id | transaction_date | +-----------+---------------------+ | 1061578 | 2014-08-05 19:36:18 | +-----------+---------------------+ 1 row in set (0.00 sec) mysql> SELECT action_id,transaction_date -> FROM transactions LEFT JOIN actions -> ON transactions.transaction_id = actions.transaction_id -> LEFT JOIN merchants ON merchant_id = idmerchants -> WHERE mdf_20 = 'a4bbf326102e3064a8d9e06558c4b5e2020ee353 ' -> AND action_type IN ('capture','sale') -> AND processor_settlement_date IS NULL -> UNION -> SELECT action_id,transaction_date FROM profitorius.actions -> WHERE transaction_id LIKE 'a4bbf326102e3064a8d9e06558c4b5e2020ee353 %' -> AND ABS(amount) = ABS('4.95') AND success = 1 -> AND action_type IN ('capture','sale') -> AND processor_settlement_date IS NULL -> ORDER BY transaction_date; +-----------+---------------------+ | action_id | transaction_date | +-----------+---------------------+ | 1061498 | 2014-08-05 18:50:11 | +-----------+---------------------+ 1 row in set (0.00 sec) #### $sql = "SELECT action_id FROM transactions LEFT JOIN actions ON transactions.transaction_id = actions.transaction_id LEFT JOIN merchants ON merchant_id = idmerchants WHERE mdf_20 = ? AND action_type IN ('capture','sale') AND ABS(amount) = ABS(?) AND success = 1 AND processor_settlement_date IS NULL ORDER BY transaction_date;"; my $sth = $dbh->prepare($sql); $sth->bind_param(1, "'1442a29888840b0b9505d34da6cd8897d153976d'"); $sth->bind_param(2, 49.95); $sth->execute; my $aref = $sth->fetchrow_array if (defined $aref); print join(', ', @$aref),"\n"; $sth->bind_param(1, "'a4bbf326102e3064a8d9e06558c4b5e2020ee353'"); $sth->bind_param(2, 4.95); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n"; $sth->finish; my $like_cond = ''; $sql = "SELECT action_id,transaction_date FROM profitorius.actions WHERE transaction_id LIKE ? AND ABS(amount) = ABS(?) AND success = 1 AND action_type IN ('capture','sale') AND processor_settlement_date IS NULL ORDER BY transaction_date;"; $sth = $dbh->prepare($sql); $like_cond = "'1442a29888840b0b9505d34da6cd8897d153976d%'"; $sth->bind_param(1,$like_cond); $sth->bind_param(2, 49.95); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n"; $like_cond = "'a4bbf326102e3064a8d9e06558c4b5e2020ee353%'"; $sth->bind_param(1,$like_cond); $sth->bind_param(2, 4.95); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n";