$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;