Efficiency of 2 queries

Database

Efficiency of 2 queries

Hi !

I have 2 inserts to a table. The second insert loooks like this:

INSERT INTO tableA
SELECT DISTINCT id1 , id2
FROM tableB A
where NOT EXISTS
( SELECT 1
FROM tableA T
WHERE T.id1 = A.id1
AND T.id2 = A.id2);

My question is would the below query be more efficient than the one above:

INSERT INTO tableA
SELECT DISTINCT id1 , id2
FROM tableB A
where T.id1 = A.id1
AND T.id2 = A.id2;

Thank you!
1 REPLY

Re: Efficiency of 2 queries

Run an explain on each query and see which is more efficient...You can put the code in SQL Assistant and hit F6 and it will display the optimizer's choice of most efficient execution plan along with resource cost estimates for every step in the plan. The plan that requires the least amount of resources is the most efficient plan. Pick that one.