Invalid Sql returns all rows

  • If you used 2-part names for your columns, it should become clear.

    select *

    from #Table1 t1

    where t1.mykey in (select t1.mykey from #BadLookup bl)

    It might look weird that the subquery is using a column from the outer query, but it's expected functionality and the base to correlated subqueries.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Interesting. After a quick search for correlated sub queries I understand why this is expected. Thanks for the help and another tool in my belt.

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply