Mysql - And Or

Discussion in 'MySQL' started by bobby9101, Mar 11, 2007.

  1. #1
    Hi,
    I am trying to use WHERE id='10' AND name!='bobby' OR username!='bobby9101'

    So pretty much if my database looks like:
    rows:
    id
    name
    username

    And I want to select WHERE id='10' BUT if name='bobby' OR username='bobby9101' don't return it.
    So One field needs to be required, but if one of the others matches, then don't return it.
    Is my code right?
    
    WHERE id='10' AND name!='bobby' OR username!='bobby9101'
    
    Code (markup):

     
    bobby9101, Mar 11, 2007 IP
  2. nanome

    nanome Peon

    Messages:
    8
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nearly there, but I would group the logic into brackets

    WHERE id='10' AND (name!='bobby' OR username!='bobby9101')
    Code (markup):
     
    nanome, Mar 11, 2007 IP
    bobby9101 likes this.
  3. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks, +rep added
     
    bobby9101, Mar 11, 2007 IP