I need to [select text where text does not contain string]

Discussion in 'Databases' started by ShiftChip, Oct 7, 2007.

  1. #1
    How would I select the text fields that do not contain a a certain sub string.
    example:

    text: "my dog likes to play games"
    Text: "my dog hates to play games"
    SELECT text where text contains "likes to play games"
    then the first text would be returned.
    Also, what would be the easiest way to bulk edit these? is there a way I could select them all then open all of them in mysqladmin?
     
    ShiftChip, Oct 7, 2007 IP
  2. mac

    mac Peon

    Messages:
    76
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The first thing that comes to mind is:

    SELECT * WHERE text_column LIKE '%dog likes to play games%'
     
    mac, Oct 8, 2007 IP
  3. trailerpark

    trailerpark Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is one way to do it. In this query the table name is mytable and the column in question is named mytext. So, I'm finding / updating the records in one easy SQL statement.

    update mytable
    set mytext = 'my cat loves catnip'
    where mytext like '%likes to play%'

    So, this query would search for every record with 'likes to play' somewhere in the text string and update that record with 'my cat loves catnip'.
     
    trailerpark, Oct 10, 2007 IP