Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

When I add Or in SQL statement it gives me records but it should not

I am not sure why is this happenning

When I write first query , it returns 0 records which is good.

SELECT id, dayType, employeeID FROM records WHERE companyID = 2 AND employeeID = 22 AND endTime IS NULL 

Then I found out that there are endtime with 0 AND NULL in column values so I added or endTime = 0, then it returns records

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT id, dayType, employeeID FROM records WHERE companyID = 2 AND employeeID = 22 AND endTime IS NULL or endTime = 0

Can someone assist please

>Solution :

You need to use parenthesis for the correct logic:

SELECT id, dayType, employeeID 
FROM records 
WHERE companyID = 2 
  AND employeeID = 22 
  AND (endTime IS NULL or endTime = 0);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading