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

DB2 :: RE: Need help on a SQL query

$
0
0
Author: AnandhaMuruganB
Subject: Reply to: Need help on a SQL query
Posted: Wed Aug 03, 2016 10:33 am (GMT 5.5)

Hi,
Please try the below query. I believe that it will give you the desired output.
For every Org_id filtered by the main query, it is going to check the sub-query (Correlated).

SELECT
A.Cust, B.Org_id, B.Status
from
TABLEA X,
TABLEB y,
TABLEC z
WHERE
x.STATUS='ACT'
AND
X.Cust_id=Z.Cust_id
AND
Z.Org_id=Y.Org_id
AND
Y.Org_id NOT IN
-- Correlated subquery
(
SELECT
ORG_ID
FROM
TABLEB Y1
where
B1.Org_id=B.Org_id
and
B.Status = 'ACT'
)
with ur;
_________________
Anand
"If you want to leave your footprint on the sand of time, do not drag your feet"


Viewing all articles
Browse latest Browse all 9405

Trending Articles