Попробуйте следующее:
Схема таблицы:
CREATE TABLE Payment_Details(
Payment_Date DATETIME,
TranNo VARCHAR(20),
RefNo VARCHAR(20),
ChequeNo VARCHAR(20));
INSERT INTO Payment_Details VALUES
('11-Nov-19','tran001','ref001','chq001'),
('11-Nov-19','tran001','ref002','chq005'),
('12-Nov-19','tran003','ref003','chq007'),
('13-Nov-19','tran017','ref001','chq005');
CREATE TABLE Payment_Confirmations(
CustomerId VARCHAR(20),
Payment_No VARCHAR(20),
Match_Status VARCHAR(20),
Payment_date DATETIME);
INSERT INTO Payment_Confirmations(CustomerId,Payment_No) VALUES
('cust_1','ref003'),
('cust_2','tran001'),
('cust_3','ref002'),
('cust_4','tran019'),
('cust_5','tran001'),
('cust_6','chq005'),
('cust_7','tran019');
SQL-запрос:
SELECT DISTINCT A.CustomerID,
A.Payment_No,
CASE WHEN B.ChequeNo IS NULL THEN 'FALSE' ELSE 'TRUE' END Match_Status,
IFNULL(b.Payment_date,'FALSE') Payment_date
FROM Payment_Confirmations A
LEFT JOIN Payment_Details B ON A.Payment_No=B.TranNo OR A.Payment_No=B.RefNo OR A.Payment_No=B.ChequeNo;
Проверкарезультат в SQL Fiddle