Skip to main content
1 of 2
paparazzo
  • 5.1k
  • 1
  • 19
  • 32

Let's just look at TableOne, TableTwo, and TableFour
Most of the condition in the "in where" in are already covered in the join
And suggest you use join on for all

Select TableTwo.Column1, DatabaseTwo..
from TableOne  
inner join TableTwo  on TableOne.Column4 = TableTwo.Column4 
inner join TableFour on TableOne.Column6 = TableFour.Column6         
where 1 = 1
--- Section 2
and TableOne.Column6 in  (Select TableOne.Column6 
                            from TableOne, TableTwo, TableFour  
                            Where TableOne.Column4 = TableTwo.Column4  -- covered in base join 
                            and TableOne.Column6 = TableFour.Column6   -- covered in base join
                            and TableFour.Column16 >= @StartDate 
                            and TableFour.Column16 <  @EndDate )

Pretty sure this is the same query
Not sure if it is faster but I doubt is is slower
The query optimizer has a better chance of filtering early

Select TableTwo.Column1, DatabaseTwo..
from TableOne  
inner join TableTwo  on  TableOne.Column4 = TableTwo.Column4 
inner join TableFour on  TableOne.Column6 = TableFour.Column6   
                     and TableFour.Column16 >= @StartDate 
                     and TableFour.Column16 <  @EndDate  
paparazzo
  • 5.1k
  • 1
  • 19
  • 32