Multiple 'OR' Conditions

Discussion in 'MySQL' started by Omzy, Jan 30, 2009.

  1. #1
    Is there a way of simplifying the following MySQL SELECT statement:

    SELECT * FROM cust WHERE (cat1='$category' OR cat2='$category' OR cat3='$category' OR cat4='$category' OR cat5='$category')
     
    Omzy, Jan 30, 2009 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Try this
    
    SELECT * FROM cust WHERE '$category' IN (cat1,cat2,cat3,cat4,cat5);
    
    Code (SQL):
     
    rohan_shenoy, Jan 30, 2009 IP
  3. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thanks for sharing, didn't know that was possible:)
     
    clinton, Jan 31, 2009 IP
  4. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yup that works very well, thank you!
     
    Omzy, Feb 3, 2009 IP