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.
The SQL AND & OR operators are used to combine multiple conditions to narrow data in an SQL statement. These two operators are called as the conjunctive operators. These operators provide a means to make multiple comparisons with different operators in the same SQL statement.
Capabilities of the SELECT Statement Three concepts from relational theory encompass the capability of the SELECT statement: projection, selection, and joining. Projection: A project operation selects only certain columns (fields) from a table.
In the real world, you will often want to select multiple columns. Luckily, SQL makes this really easy. To select multiple columns from a table, simply separate the column names with commas!
Using AND, OR, and NOT together. You can combine the three logical operators in a compound condition. Your DBMS uses SQL's precedence rules to determine which operators to evaluate first.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With