Can anyone help me to modify the sql below to make it run faster? Thanks.
SELECT DISTINCT B.CLT_NBR ,
CASE
WHEN B.CLT_NBR IN (SELECT CLT_NBR FROM A) THEN 'YES'
ELSE 'NO'
END AS CHECK
FROM B
Use left join instead of a subquery:
SELECT DISTINCT B.CLT_NBR ,
CASE
WHEN A.Id IS NOT NULL THEN 'YES'
ELSE 'NO'
END AS CHECK
FROM B
LEFT JOIN A ON(B.CLT_NBR = A.CLT_NBR)
Note: instead of the A.Id I've used you need to use A's primary key.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.