how to delete the odd ids please???

Discussion in 'Databases' started by crazy.works, Sep 27, 2009.

  1. #1
    hello, i have database, in it lets say 50k row, i need to delete the rows with the odd ids... like "Delete From Table Where id (is odd)".
    so how can i do that ? what is the mysql command for that please?
    thanks
     
    crazy.works, Sep 27, 2009 IP
  2. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use the MOD() function or operator:

    DELETE FROM table WHERE id%2;
    Code (markup):
     
    chadsmith, Sep 27, 2009 IP
  3. crazy.works

    crazy.works Peon

    Messages:
    304
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks a lot
     
    crazy.works, Sep 27, 2009 IP
  4. mji2010

    mji2010 Active Member

    Messages:
    762
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #4
    wouldn't have have to use:
    delete * from table where id%2=1

    ?
     
    mji2010, Sep 27, 2009 IP
  5. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Not in this case since it could only return a remainder of 1 (which also means true) or 0 (which also means false) If he wanted even numbers instead he'd have to use id%2=0 so it would return true for odd numbers
     
    chadsmith, Sep 27, 2009 IP
  6. Traffic-Bug

    Traffic-Bug Active Member

    Messages:
    1,866
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Are you trying to delete the alternate rows (oddly numbered rows) or the rows where the field id is odd. Both case the query is different
    example
    rownum id
    1 5
    2 7
    3 8
     
    Traffic-Bug, Sep 27, 2009 IP