I am not getting the output as expected, because
AND ta.task_status_type_id NOT IN ( 10 )
is not working in below query.
SELECT ta.task_id AS id, u.employee_id AS employee_id, ta.task_status_type_id FROM task_assignments AS ta, users AS u WHERE u.id = ta.user_id AND ta.id IN ( SELECT max ( ta.id ) OVER ( partition BY ta.task_id ) AS id FROM task_details AS td, task_assignments AS ta WHERE td.task_id = ta.task_id AND td.developer_employee_id IS NULL AND ta.task_type_id IN(6,7) AND ta.task_status_type_id NOT IN ( 10 ) AND ta.task_status_type_id IN ( 9 ) );
Please help in resolving the error.
An educated guess (for lack of more information):
NOT IN (...)
returnsNULL
if anyNULL
values are involved and the tested value is not in the list. But onlyTRUE
qualifies in aWHERE
clause.is transformed to:
equivalent to:
If any of these values (on either side of the operator) is
NULL
, you get:That's:
And
NULL
is equivalent toFALSE
in aWHERE
clause. OnlyTRUE
qualifies.This has been known to cause disbelieve in users unfamiliar with tri-valued logic.
Use
IS DISTINCT FROM
orNOT EXISTS
instead. OrLEFT JOIN / IS NULL
.Example (more guesswork)
In this particular case, you don't need the incriminated expression at all
If you are secretly using a list of values to be excluded that could share elements with the inclusion list:
Or you weed out NULL values.
Or you avoid common elements in inclusion and exclusion list.