dudejma Posted July 28, 2011 Share Posted July 28, 2011 I was just wondering if you could use OR in the where clause. I've never done it before. For example: $sql = "SELECT * FROM users WHERE status='1' OR status='2' OR status='3' OR status='4'" What it is, I have users where their status is 0 meaning that they're not suspended, but they're just not activated. Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/243109-can-you-use-or-in-the-where-clause/ Share on other sites More sharing options...
Pikachu2000 Posted July 28, 2011 Share Posted July 28, 2011 You could have tried it and had your answer in the time it took you to post the thread and wait for a response, but yes you can do that. Quote Link to comment https://forums.phpfreaks.com/topic/243109-can-you-use-or-in-the-where-clause/#findComment-1248601 Share on other sites More sharing options...
AyKay47 Posted July 28, 2011 Share Posted July 28, 2011 You could have tried it and had your answer in the time it took you to post the thread and wait for a response, but yes you can do that. such a gentlemen Pikachu.. but you do have a point Quote Link to comment https://forums.phpfreaks.com/topic/243109-can-you-use-or-in-the-where-clause/#findComment-1248602 Share on other sites More sharing options...
kickstart Posted July 28, 2011 Share Posted July 28, 2011 Hi You can, but the confusion comes when you mix OR and AND, and come across operator precedence. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243109-can-you-use-or-in-the-where-clause/#findComment-1248610 Share on other sites More sharing options...
dudejma Posted July 28, 2011 Author Share Posted July 28, 2011 I was going to try it but then I'd have to make the database and go through all that which I'm not quite to yet. I'm just planning out things before I completely smart. But well said Pikachu(: Quote Link to comment https://forums.phpfreaks.com/topic/243109-can-you-use-or-in-the-where-clause/#findComment-1248728 Share on other sites More sharing options...
silkfire Posted July 28, 2011 Share Posted July 28, 2011 Just a tip matey: in this case you don't need to use OR because you're matching against the SAME column. Plus, it's numbers which makes things even easier: $sql = 'SELECT * FROM users WHERE status BETWEEN 1 AND 4'; Quote Link to comment https://forums.phpfreaks.com/topic/243109-can-you-use-or-in-the-where-clause/#findComment-1248768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.