Left Join or Not Exists

10

I needed to retrieve information that was in one table, but not in another. Searching found that NOT EXISTS would serve this purpose, but I saw that the Left Join has the same result:

NOT EXISTS

select pedido from logintegracao as A
where not exists (select * from pagamento as B where B.idPedido = A.Pedido)

Execution Plan:

LEFTJOIN

select*fromlogintegracaoasAleftjoinpagamentoasBonA.Pedido=B.idpedidowhereB.idpedidoisnull

ExecutionPlan

Which Query would have the best performance? Are both ways correct?

    
asked by anonymous 09.12.2015 / 19:11

1 answer

1

The two ways are correct, but I believe that LEFT JOIN is better because it does not use subselect .

    
18.12.2015 / 19:57