Why difference between Inner Join and select in columns?

Venkata Vunnam 21 Reputation points
2022-08-14T13:30:21.597+00:00

The following queries are used to find out the common rows between TableX and (TableY and TableZ).
Why the difference and where am I missing?

SELECT count(*) from TableX
INNER JOIN TableY on TableX.ColX=TableY.ColX
INNER JOIN TableZ on TableY.ColID= TableZ.ColID
where TableZ.[DtCreated] <= '2015-08-02 23:59:59.998' and TableZ.EntityID = 31068
---The above query gives 107 Rows

select count(*) from TableX where ColX in (select ColX from TableY INNER JOIN TableZ on TableY.ColID= TableZ.ColID where TableZ.[DtCreated] >= '2015-08-02 23:59:59.998' and Tablez.EntityID = 31068)

      ---The above query gives 900,000 rows  
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,547 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 111.7K Reputation points
    2022-08-14T13:45:12.013+00:00

    I think that you must use '<=' or '>=' in both of queries.


0 additional answers

Sort by: Most helpful