how to delete rows by the id units number please ?

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

  1. #1
    Hello, i wanna delete the rows by the the id units number, i mean i wanna do it like this..."Delete From table Where (id unit number is 2)"
    so the command will delete the all rows with 2 in it's id unit number, for example it will delete the rows with the ids like 2, 12, 22, 32, 42, 52,.. 112, 122... etc
    so how to delete rows by the units number ? 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 MOD() for this as well.

    DELETE FROM table WHERE MOD(id,10)=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. chisara

    chisara Peon

    Messages:
    141
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Does that really remove all id's with a 2 in it ?
    I would have tought you needed to do a cast of the INT ->Varchar and then a like (%2% ) operation.

    You case is any ID with a 2 in it, so 220 and 3325 are also valid for deletion in your description.
     
    chisara, Sep 28, 2009 IP
  5. jkapadia1983

    jkapadia1983 Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    DELETE FROM table WHERE to_char(id_unit) like '%2%';
     
    jkapadia1983, Sep 30, 2009 IP