Author Topic: Multiple OR Statement Question  (Read 370 times)

0 Members and 1 Guest are viewing this topic.

Offline NoSaltTopic starter

  • Enthusiast
  • Posts: 75
  • Gender: Male
    • View Profile
Multiple OR Statement Question
« on: February 24, 2010, 01:56:21 PM »
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:

Code: [Select]
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:

Code: [Select]
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.  :)
« Last Edit: February 24, 2010, 02:00:17 PM by NoSalt »

Offline NoSaltTopic starter

  • Enthusiast
  • Posts: 75
  • Gender: Male
    • View Profile
Re: Multiple OR Statement Question
« Reply #1 on: February 24, 2010, 02:01:31 PM »
Nevermind ... I got it after some more fooling around. Here is the answer:

Code: [Select]
SELECT * FROM EVENT_TABLE where EVENT_TYPE_ID = 1 || 2 || 3 || 6 || 10 || 11 || 13 || 15 || 16 || 34;

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,444
  • Gender: Male
    • View Profile
Re: Multiple OR Statement Question
« Reply #3 on: February 24, 2010, 02:51:46 PM »
No kidding...

Code: [Select]
SELECT * FROM EVENT_TABLE where EVENT_TYPE_ID IN( 1,2,3, 6, 10, 11, 13, 15, 16, 34);
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

Offline NoSaltTopic starter

  • Enthusiast
  • Posts: 75
  • Gender: Male
    • View Profile
Re: Multiple OR Statement Question
« Reply #4 on: February 24, 2010, 03:07:30 PM »
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.   :D