SQL - improve NOT EXISTS query performance

前端 未结 7 1942
名媛妹妹
名媛妹妹 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:41

    insert into customers 
    select * 
    from newcustomers 
    where customerid not in (select customerid 
                             from customers)
    

    ..may be more efficient. As others have said, make sure you've got indexes on any lookup fields.

提交回复
热议问题