SGR
SGR

Reputation: 403

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.

Upvotes: 1

Views: 47

Answers (1)

Mahesh Madushanka
Mahesh Madushanka

Reputation: 2998

USE NOT IN for those two or operations

$woquery = $dbc->prepare("SELECT * FROM workorder WHERE statusID NOT IN( 15, 12) ORDER BY dateIn ASC"

Upvotes: 3

Related Questions