This works as expected and required by the SQL standard. If a subquery references a column that is not available in the tables of the subquery, but is a valid column in the outer query, the value from the outer query's column is used.
So the query:
SELECT DISTINCT SubLOBID
FROM tblA
WHERE AdviceRecordID IN (SELECT AdviceRecordID
FROM tblB);
Is in fact a co-related subquery and is parsed and executed as:
SELECT DISTINCT SubLOBID
FROM tblA
WHERE AdviceRecordID IN (SELECT tblA.AdviceRecordID
FROM tblB);
So for each row in tblA
the subquery returns the value of tblA.AdviceRecordID
once for each row in tblB
and compares that to the rules of the IN
operator.
That's why the query as a whole is valid, and behaves like no where clause was used as the above is equivalent to:
SELECT DISTINCT SubLOBID
FROM tblA
WHERE AdviceRecordID IS NOT NULL;
And if there are no NULL values in the column AdviceRecordID then the WHERE
clause is not filtering out anything.