1

I was wondering how can I change my query to JOIN one with the same result:

update CDR 
set CDR_TYPE = 'ON_NET' 
where anum in (select subscriber 
               from DEGREE 
               where sub_type = 'MTN')
  and bnum in (select subscriber 
               from DEGREE 
               where sub_type = 'MTN')

FYI: I am using ORACLE database.

Best Regards.

Ashish Gaur
  • 2,030
  • 2
  • 18
  • 32
Ali
  • 1,759
  • 2
  • 32
  • 69

2 Answers2

1

You could use a WITH clause to get rid of the repeated subquery.

WITH subquery AS (select subscriber 
               from DEGREE 
               where sub_type = 'MTN')
UPDATE cdr
SET cdr_type = 'ON_NET' 
WHERE anum IN (subquery)
  AND bnum IN (subquery);
Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
0
UPDATE 
(SELECT cdr_type 
 FROM cdr c
 INNER JOIN degree d
 ON c.anum = d.subscriber 
    AND c.bnum = d.subscriber
 WHERE d.sub_type = 'MTN'
) t
SET t.cdr_type = 'ON_NET'
Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133