SQL - improve NOT EXISTS query performance

前端 未结 7 1943
名媛妹妹
名媛妹妹 2021-02-07 09:08

Is there a way I can improve this kind of SQL query performance:

INSERT
INTO ...
WHERE NOT EXISTS(Validation...)

The problem is when I have ma

7条回答
  •  长发绾君心
    2021-02-07 09:37

    Outer Apply tends to work for me...

    instead of:

    from t1
    where not exists (select 1 from t2 where t1.something=t2.something)
    

    I'll use:

    from t1
    outer apply (
        select top 1 1 as found from t2 where t1.something=t2.something
    ) t2f
    where t2f.found is null
    

提交回复
热议问题