SGR SGR - 1 year ago 87
SQL Question

SQL OR functioning like AND

This is the relevant line of code:

$woquery = $dbc->prepare("SELECT * FROM workorder WHERE statusID <> 15 OR statusID <> 12 ORDER BY dateIn ASC");

The problem I am having is that with this code, the OR function seems to be working like an AND function.

If I change it to (for example):

statusID <> 15 OR statusID <> 15

Then it correctly excludes records with 15 for statusID, same if I set it to 12

If I have just a single WHERE function with no OR, then it also filters correctly. However, when I have both, it filters neither 12 or 15.

Answer Source

USE NOT IN for those two or operations

$woquery = $dbc->prepare("SELECT * FROM workorder WHERE statusID NOT IN( 15, 12) ORDER BY dateIn ASC"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download