should i prefer join over exists or in

Rajesh Kumar Yadav 20 Reputation points
2024-04-16T07:20:37.7866667+00:00

hi,

I have seen people use exists when exists is required and no cols are required in select.

But I notice sometimes exists slows down and join performs better

q1) is there any news i should know ,  that one should not use exists or in , and should go for  join etc etc

 

yours sincerely

Azure SQL Database
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,065 questions
SQL Server | SQL Server Transact-SQL
Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Greg Low 1,980 Reputation points Microsoft Regional Director
    2024-04-18T00:59:52.34+00:00

    There is no simple answer to that.

    However, in general, I find that the SQL Server optimizer does a much better job of optimizing EXISTS clauses than the equivalent joins.

    Also, in the end, an EXISTS clause is often much clearer for someone else reading the code, as it generally shows the intent of the code better. Finally, it often keeps the existence test within a single predicate, which again avoids confusing the rest of the query with the existence aspects.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.