Quantcast
Channel: IBM Mainframe Computers Forums
Viewing all articles
Browse latest Browse all 8500

DB2 :: RE: Need help on a SQL query

$
0
0
Author: chandan.inst
Posted: Tue Aug 09, 2016 2:49 pm (GMT 5.5)

Hi,

I guess checking for ORG_ID in subquery will not work here..

We will need ti check if that customer has a single active row present then do not select it as Rahul suggested in one of the answer

Check if below works..

Code:
Select X.Cus_id, Y.Org_id, Y.Status
From TableA X, TableB Y, TableC Z
Where X.Cus_id = Z.Cus_id
AND Y.Org_id = Z.Org_id
AND X.Status = 'ACT
NOT EXISTS
(
SELECT 1 FROM TABLE1, TABLE3, TABLE2
    WHERE TABLE1_CUSTID = X.CUST_ID
      AND TABLE1.CUS_ID = TABLE3.CUS_ID
      AND TABLE3.ORG_ID = TABLE2.ORG_ID
      AND TABLE2.END_DT IS NULL
      AND TABLE2.STATUS IN ('ACT','SUSP'))
      FETCH FIRST ONE ROW ONLY 
)


Viewing all articles
Browse latest Browse all 8500

Trending Articles