problem with multiple conditions

Discussion in 'MySQL' started by mahmood, Mar 12, 2006.

  1. #1
    Hi
    I have a problem with multiple queries and hope I can convey myself clearly.

    say I have to select part of a table
    SELECT * FROM mytable WHERE condition1 OR condition2 AND condition3 OR condition4
    PHP:
    But this doesn't give what I want, It seems that sql interpret it with "condition1 OR condition2 OR condition3 OR condition4".

    what I want is the equivalent of this (condition1 OR condition2) AND (condition3 OR condition4). Any idea?
     
    mahmood, Mar 12, 2006 IP
  2. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just use
    (condition1 OR condition2) AND (condition3 OR condition4)

    you were so close..
     
    Dejavu, Mar 12, 2006 IP
  3. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #3
    yep, use the parens to force the way the expressions are evauled. If you are sloppy, hehe, like that was, you get the mysql interprutation of the order of presidence.
     
    noppid, Mar 12, 2006 IP
  4. mahmood

    mahmood Guest

    Messages:
    1,228
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks

    I didn't test it because I though it was so good to be true to me.:)
     
    mahmood, Mar 12, 2006 IP