kevin_marcus
kevin_marcus

Reputation: 277

MySQL SELECT If Statement WHERE Condition

I created a module for rendering overtime. In the module you will select your approving person and it will be maximum of 3 persons.

The scenario is that I will display all approved overtimes if manager1_date is not NULL, manager2_date is not NULL and manager3_date is not NULL. But as i said, it can be only 1,2 or 3 approving person. what if i applied then i have only 2 approving persons, it should be if manager1_date is not NULL and manager2_date is not NULL.

I tried this query:

Select * from table1 
where manager1_date is not null 
AND (manager2_date is not null or manager3_date is not null)

In PHP, it displays the record but the record has 3rd approving person which is manager3_date is NULL. it should not display the record until the approving persons are filled out.

Upvotes: 0

Views: 111

Answers (2)

AllInOne
AllInOne

Reputation: 1450

I think you are saying that all three managers must approve. If so your query would be:

SELECT *
FROM table1 
WHERE manager1_date IS NOT null 
AND manager2_date IS NOT null 
AND manager3_date IS NOT null

Upvotes: 1

Tom
Tom

Reputation: 6663

I'm not sure if I understand your question, but if you need to see when all three manager dates are not null, get rid of the "or".

Select * 
from   table1 
where  manager1_date is not null 
       AND manager2_date is not null 
       AND manager3_date is not null

Upvotes: 0

Related Questions