delete from mysql with condition

Discussion in 'PHP' started by sabato, Jun 25, 2011.

  1. #1
    Hi,

    I have mysql table with links in it. I want to delete links that extension is not .txt.
    I am wondering if it is possible to delete without retrieve links and check their extension first.

    Thanks
     
    sabato, Jun 25, 2011 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    
    DELETE FROM relation WHERE attribute NOT LIKE '%.txt'
    
    Code (markup):
    Not sure how efficient this is. You may want to normalise your database schema so you have a relation (table) that holds links and then a separate one that holds their extensions. That way you can perform many operations on the two relations. However, the above should work.
     
    BRUm, Jun 25, 2011 IP
  3. sabato

    sabato Member

    Messages:
    407
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    43
    #3
    Hi,
    it works like charm. Thanks a lot
     
    sabato, Jun 25, 2011 IP
  4. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #4
    No problem mate, I knew Databases module would pay off :p
     
    BRUm, Jun 25, 2011 IP