How do I word this MySQL command correctly please?

Discussion in 'PHP' started by egdcltd, Aug 7, 2007.

  1. #1
    DELETE all instances FROM bnt_ships WHERE ship_name contains the word xenobe
    PHP:

     
    egdcltd, Aug 7, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    DELETE FROM bnt_ships WHERE ship_name LIKE '%xenobe%'
    
    Code (sql):
     
    nico_swd, Aug 7, 2007 IP
  3. Providence

    Providence Peon

    Messages:
    568
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    DELETE FROM bnt_ships WHERE ship_name LIKE '% xenobe %'
    Code (markup):
    Or this if you want to delete records with xenobe only instead of deleting sdhoxenobesldf
     
    Providence, Aug 7, 2007 IP
  4. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks. I think the first option is more what I need.
     
    egdcltd, Aug 8, 2007 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    But it doesn't recognise the word if it has punctuation. Not that it matters in this case but you could use:
    DELETE FROM bnt_ships WHERE MATCH (ship_name) AGAINST ('xenobe')
    Code (markup):
     
    krt, Aug 8, 2007 IP
  6. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Actually, that might matter. Every record that needs deleting begins Xenobe-
     
    egdcltd, Aug 8, 2007 IP
  7. Supergeek

    Supergeek Peon

    Messages:
    138
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If they begin with an exact phrase, don't use the % at the front.

    For example, %xenobe% would match
    rexenobe
    xenober
    xenobes

    whereas xenobe-% would not match noxenobe but would match xenobe-10, xenobe-fred, whatever. % is a wildcard.
     
    Supergeek, Aug 8, 2007 IP