Reputation: 85
SELECT *
FROM REVIEW
WHERE REVIEWERID =5 AND APPRAISEECONFIRMYN='Y' AND HRCONFIRMYN = NULL
Are 2 'AND' conditions allowed like this? I'm not getting the correct output. There are 2 records in the database that fulfil the above conditions. When I remove the last condition 'HRCONFIRMYN = NULL'
and execute, I get the correct output.
How can this be solved? I need to check all 3 conditions whilst searchng the records.
Upvotes: 5
Views: 62804
Reputation: 79979
To compare the NULL
values, you have to use the IS NULL
predicate instead of = NULL
like so:
SELECT *
FROM REVIEW
WHERE REVIEWERID = 5
AND APPRAISEECONFIRMYN = 'Y'
AND HRCONFIRMYN IS NULL
Upvotes: 13
Reputation: 263893
OR
insteadIS NULL
when comparing with NULLsquery,
SELECT *
FROM REVIEW
WHERE (REVIEWERID =5 AND APPRAISEECONFIRMYN='Y') OR
HRCONFIRMYN IS NULL
Upvotes: 2