NoSalt Posted February 24, 2010 Share Posted February 24, 2010 Hello All I have a MySQL question about multiple OR statements; I guess it could also be about multiple AND statements. Say I have the following statement: SELECT * FROM EVENT_TABLE where EVENT_TYPE_ID = 1 OR EVENT_TYPE_ID = 2 OR EVENT_TYPE_ID = 3 OR EVENT_TYPE_ID = 6 OR EVENT_TYPE_ID = 10 OR EVENT_TYPE_ID = 11 OR EVENT_TYPE_ID = 13 OR EVENT_TYPE_ID = 15 OR EVENT_TYPE_ID = 16 OR EVENT_TYPE_ID = 34; I was hoping that there was a shorter, more efficient way to do this. Maybe like this: SELECT * FROM EVENT_TABLE where EVENT_TYPE_ID = {1 OR 2 OR 3 OR 6 OR 10 OR 11 OR 13 OR 15 OR 16 OR 34}; So far, however, I have had no luck stumbling on the key. Is there a way to do what I want or am I stuck with the "hammer approach"? Thanks for reading and have a good day. Quote Link to comment https://forums.phpfreaks.com/topic/193263-multiple-or-statement-question/ Share on other sites More sharing options...
NoSalt Posted February 24, 2010 Author Share Posted February 24, 2010 Nevermind ... I got it after some more fooling around. Here is the answer: SELECT * FROM EVENT_TABLE where EVENT_TYPE_ID = 1 || 2 || 3 || 6 || 10 || 11 || 13 || 15 || 16 || 34; Quote Link to comment https://forums.phpfreaks.com/topic/193263-multiple-or-statement-question/#findComment-1017609 Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2010 Share Posted February 24, 2010 http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html#function_in Quote Link to comment https://forums.phpfreaks.com/topic/193263-multiple-or-statement-question/#findComment-1017613 Share on other sites More sharing options...
fenway Posted February 24, 2010 Share Posted February 24, 2010 No kidding... SELECT * FROM EVENT_TABLE where EVENT_TYPE_ID IN( 1,2,3, 6, 10, 11, 13, 15, 16, 34); Quote Link to comment https://forums.phpfreaks.com/topic/193263-multiple-or-statement-question/#findComment-1017661 Share on other sites More sharing options...
NoSalt Posted February 24, 2010 Author Share Posted February 24, 2010 You are correct ... I came here to post that my initial finding didn't work after all. Yours works absolutely perfectly. Thank you very much for recognizing my incorrectness and rectifying the situation. Next time I'll know not to be so hasty with my "conclusions". Have a great day. Quote Link to comment https://forums.phpfreaks.com/topic/193263-multiple-or-statement-question/#findComment-1017672 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.