Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL 'select' Query with 3 conditions

Tags:

sql

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.

like image 932
sanu j Avatar asked Nov 25 '12 14:11

sanu j


People also ask

How do I select multiple conditions in SQL?

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.

What are the 3 capabilities of SQL select 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.

How do I select 3 columns in SQL?

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!

Can we use three and in SQL?

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.


1 Answers

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
like image 171
Mahmoud Gamal Avatar answered Sep 27 '22 17:09

Mahmoud Gamal