That was my gut reaction initially, Fabio ... the second one just seemed like it should be faster. Thanks for verifying. =)
~~Bonnie
>>
>You could filter out FK with NULLs easily (if they are the problem).>>
>>Yes, I know ... but the second example you gave seemed much simpler, so I went with it. <s> I don't know which one would be faster, but I don't have enough data to benchmark it right now.
>>
>
>second; MSSQL optimize it.
>
>Fabio
>
>>Thanks,
>>~~Bonnie
>>
>>
>>
>>
>>>Hi Bonnie,
>>>
>>>You could filter out FK with NULLs easily (if they are the problem).
>>>
>>>SELECT * FROM mytable mt1
>>> WHERE mt1.FK IS NOT NULL
>>> AND NOT EXISTS ( SELECT * FROM mytable mt2
>>> WHERE mt2.FK = mt1.FK and mt2.date > mt1.date)
>>>
>>>>Thanks Sergey! The first one didn't work (I assume because of the fact that there can be NULLs in the FK), but the second one worked fine. I needed to tweak it a little more, because I also need to join the second table to further weed out some criteria, but I figured that out easily enough. You gave me a push in the right direction, thanks!!! =)
>>>>