Link to home
Start Free TrialLog in
Avatar of jsteenkist
jsteenkist

asked on

any faster solution for NOT EXISTS?

Is there a faster solution for the following code:?

SELECT b.risk_rating_code,
       b.risk_type_code,
       b.rating_approach_code,
       MIN(b.risk_period)       AS number_of_records
 INTO  #counts
 FROM  risk_rating_value b
 WHERE b.record_valid_until IS NULL
 AND NOT EXISTS
      (SELECT 1 FROM risk_rating_value c
       WHERE c.risk_rating_code = b.risk_rating_code AND c.risk_type_code = b.risk_type_code AND c.rating_approach_code = b.rating_approach_code
       AND c.risk_period >= b.risk_period AND c.record_valid_until IS NULL AND c.pd_median <> b.pd_median )       
GROUP BY b.risk_rating_code, b.risk_type_code, b.rating_approach_code
ORDER BY b.risk_rating_code, b.risk_type_code, b.rating_approach_code

and i mean the NOT EXISTS construction. im guessing that will take much time.

thnx.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial