Author: RahulG31
Subject: Reply to: Need help on a SQL query
Posted: Fri Jul 22, 2016 1:31 am (GMT 5.5)
How much data do you have on the tables? I have to ask this as it's easier to do a NOT IN for Cus_id but if you have millions of Cus_id then it probably won't work/take a long time.
If not much data then try this (I know it only gives cus_id but try it and let us know):
.
Subject: Reply to: Need help on a SQL query
Posted: Fri Jul 22, 2016 1:31 am (GMT 5.5)
How much data do you have on the tables? I have to ask this as it's easier to do a NOT IN for Cus_id but if you have millions of Cus_id then it probably won't work/take a long time.
If not much data then try this (I know it only gives cus_id but try it and let us know):
Code: |
SELECT CUS_ID FROM TABLE1 WHERE CUS_ID NOT IN ( SELECT CUS_ID FROM TABLE1, TABLE3, TABLE2 WHERE CUS_ID_STATUS = 'ACT' AND TABLE1.CUS_ID = TABLE3.CUS_ID AND TABLE3.ORG_ID = TABLE2.ORG_ID AND TABLE2.COMPANY_ID = 'AG' AND TABLE2.END_DT IS NULL AND TABLE2.STATUS IN ('ACT','SUSP')) AND CUS_ID_STATUS = 'ACT' |
.