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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,977 questions
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.
2,936 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
101 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,652 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Greg Low 1,770 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.