Here you have to make small changes:
First of all, add the TOP clause to the subquery to force the query to return only one record in this table2. A subquery like this should only return a scalar value.
Secondly, a subquery can contain only one column in the list of columns, so the return value must be scalar.
Finally, you cannot filter the subquery or any made column in the select clause. Therefore, I recommend either using "join" or "exists" .
Select col1, col2 from table1 left outer join table2 on table1.key = table2.key where not table2.key is null
Or that:
Select col1, col2 from table1 inner join table2 on table1.key = table2.key
Or this one:
Select col1, col2 from table1 where exists ( select * from table2 where table2.key = table1.key and not table2.somethingelse is null
Greetings
Rikki source share