Search code examples
sqlsql-serverperformanceselectinner-join

Difference between using IN SELECT and INNER JOIN


I want to know if there is performance difference in using

SELECT Table1.*
FROM Table1
WHERE Col1 IN (SELECT Col2 FROM Table2)

AND

SELECT Table1.*
FROM Table1 INNER JOIN Table2
ON Table1.Col1 = Table2.Col2

Solution

  • Usually joins will work faster than subquery. But sometimes the performance may depend on the data in the tables or other factors.

    You can write your SQL by JOIN or SUBQUERY, SQL Server will always transform it on an execution plan.

    You can see more: https://www.essentialsql.com/what-is-the-difference-between-a-join-and-subquery/