-2
SELECT
t3.transaction_id,
t3.transaction_no,
t3.retrivel_ref_no,
t3.transaction_type,
t3.reversal_flag,
t3.expires_on,
t3.currency_code,
t3.message_reason_code,
t4.sales_person_id,
t3.card_no,
t3.transaction_amount,
t3.transmission_date_time
FROM TRANSACTION AS t4
INNER JOIN
( SELECT
t2.transaction_id,
t2.transaction_no,
t2.retrivel_ref_no,
t2.transaction_type,
t2.reversal_flag,
t2.transmission_date_time,
t2.transaction_amount,
t2.card_no,
t2.expires_on,
t2.currency_code,
t1.message_reason_code
FROM
( SELECT*
FROM transaction_pci_details
WHERE message_reason_code LIKE '%OUT%'||
message_reason_code LIKE '%FAILED%'
) AS t1
INNER JOIN
(
SELECT*
FROM transaction_pci_details
WHERE action_code LIKE '%REQ%'
) AS t2
ON t1.transaction_no = t2.transaction_no
) AS t3
ON t4.transaction_id = t3.transaction_id;