I have some doubts on when to use IN operator and Exists operator. I know what they both are.
Say, I have this query:
Insert into AuditCardTypeBenefit_New(AuditID, AuditType, CardTypeBenefitID, EventCode,
CardTypeGroupID, AgeFrom, AgeTo, Gender,
CreateBy, CreateDate, Status,
CancelReason, LastChangeBy, LastChangeDate)
select
AuditID, AuditType, CardTypeBenefitID, EventCode,
CardTypeGroupID, AgeFrom, AgeTo, Gender,
CreateBy, CreateDate, Status,
CancelReason, LastChangeBy, LastChangeDate
from
AuditCardTypeBenefit
where
exists (select * from PromotionEvent_New
where PromotionEvent_New.EventCode = AuditCardTypeBenefit.EventCode)
I am inserting records to a table where the records must also exist in promotionevent_new (eventcode)
to exist in this table I am inserting. This query works fine. I was wondering would it be better to use an alternative such as:
where EventCode in (select EVENTCODE from PromotionEvent)
Both queries return the same result - but which would be better for my case?