An example for data in my table
post_id|post_title|post_status
1 i 1
2 love 0
3 sof 0
i’ve problem with (OR)
i am trying this condition
WHERE post_status = '1' AND post_id = '1' OR post_title = 'i';
//it should return with i
// but it returned with love,sof
The problem is caused because of (OR) at the end in the condition
it has been disabled the earlier part of the condition
So, How i can use OR properly?
i want search in posts by both columns, post_id and post_title
NOTE:
i can’t move post_status='1' to the end of the condition for some reason, it should be in begain
You just need to group logically with
(), otherwise, theORcondition, whenever true, will supercede the required conditionpost_status = 1regardless of whether it is matched.You should always be thinking about logical groups and precedence when constructing multipart
WHEREclauses, but especially when making use of the logicalOR, as it can quickly derail the rest of your clause.