Muhammed Ashik Muhammed Ashik - 1 year ago 92
MySQL Question

Multiple AND/OR logic messed up

I need to get my data when

and status= In use or Pending or Deleted.
But I am getting extra data not sure why.

I am getting extra data from


MySQL query is:

SELECT * FROM `registered_bicycle`
WHERE (`userID`='4')
AND (`status`='In Use')
OR (`status`='Pending')
OR (`status`='Deleted')

enter image description here

Answer Source

Try this instead:

WHERE `userID` = '4'
AND `status` IN('In Use','Pending','Deleted')

Your and/or logic got mixed up because of lacking proper parentheses. Also you can use IN instead of multiple OR clauses.

Btw, IN is just the short form of OR

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download