: .
SQL Server , , NOT IN . :
select * from table where id not in (select id from tableB where somecondition(x))
When a subquery contains a list of identifiers, the query returns data as expected. But when the subquery returns nothing, the query will still return data, but then it gets stuck.
I changed the request to the following and solved the problem:
select * from table where id not in (select id from tableB where somecondition(x) **union all select 0**)
which ensures that the subquery contains at least one number.
source
share