通常、次のようなSQLを使用している場合:
select * from employees where epmloyeeTypeId in (select id from type where name = 'emp')
私where
はこれで置き換えます:
select e.* from employees e
inner join type t on t.id=e.epmloyeeTypeId and t.name = 'emp'
それが句not in
ではなく(以下のように)である場合、逆で同じことをすることは可能in
ですか?
INSERT into Subscriptions(ProjectId, RecordTypeCID, NTID, Active, Added, LastUpdate, UpdateBy)
SELECT @ProjectId, RecordTypeCID, @NTID, 1, GETDATE(), GETDATE(), @NTID
FROM @Check CHK
WHERE CHK.ActiveStatus=1
And Not Exists (SELECT SubscriptionId FROM Subscriptions
WHERE ProjectId=@ProjectId
and NTID=@NTID
and RecordTypeCID = CHK.RecordTypeCID
)
追加の考慮事項
私はこれを行うことができます:
INSERT INTO Subscriptions(ProjectId, RecordTypeCID, NTID,Active, Added, LastUpdate, UpdateBy)
SELECT @ProjectId, RecordTypeCID, @NTID,1, GETDATE(), GETDATE(), @NTID
FROM @Check CHK
LEFT JOIN Subscriptions subs ON subs.RecordTypeCID = CHK.RecordTypeCID
AND NTID = @NTID
AND ProjectId = @ProjectId
AND CHK.ActiveStatus = 1
AND subs.SubscriptionId IS NULL