Delete all rows where name has "prefix_sdfsfdf"

Discussion in 'Databases' started by adbox, Sep 24, 2009.

  1. #1
    Hey I've been playing around with a sql command to do this and I botched it a couple of times and dropped all rows instead of the rows that had the field prefix I was targeting

    here is what I want to do

    DELETE * FROM table WHERE fieldname LIKE 'prefix_'

    but the above didnt do what I wanted. What have I done wrong?

    adbox
     
    adbox, Sep 24, 2009 IP
  2. renownedmedia

    renownedmedia Well-Known Member

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    100
    #2
    DELETE FROM table WHERE fieldname LIKE 'prefix_%'
     
    renownedmedia, Sep 24, 2009 IP
  3. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    RenownedMedia provided the correct syntax for your SQL Statement. In your statement, the data had to exactly match "prefix_" in order to be deleted and none of your data matched that. Adding the percent sign acts as a wildcard. In this case, prefix_% means anything anything that begins with prefix_

    %prefix_ means anything that ENDS in prefix_

    %prefix_% means if the data contains prefix_ anywhere in the data, beginning, middle, or end.
     
    nyxano, Sep 24, 2009 IP