The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

New to SQL: How can I search for & replace specific info?

Discussion in 'Database Discussions' started by Huusoku, Aug 5, 2011.

  1. Huusoku

    Huusoku Active Member

    Joined:
    Dec 24, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Hello cP,

    I have a question regarding how to create a database search and replace query.

    I know how to use replace(field, ‘string to find’, ‘replace string’); but I am wondering how to use this when I have a search query instead of a string to find.

    For instance, when I run:
    Code:
    SELECT * FROM `db`.`table`
    WHERE ( 
      CONVERT( `column` USING utf8 ) 
      LIKE '%string_to_find%'
    )
    I get a huge list of rows from the table I'm searching in whose column contains my search string. But what I don't know how to do is replace a string of a different column of this same table using only these results.

    So, for instance, if I had a database called "db" and its table called "table" contained the following data:

    id color size
    1redL
    2greenS
    3redM

    What query would I use to search for all matches of the color red, and then replace the size of only the rows that have the color red with the size XL?

    Thanks!
    BigMike
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,446
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
  3. Huusoku

    Huusoku Active Member

    Joined:
    Dec 24, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Hmmmmm, okay. I posted it here because this forum is described as "Everything database-related including database users, MySQL®, PostgreSQL, phpMyAdmin and phpPgAdmin.", and this is database related for MySQL.

    Huusoku
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Everything database related in regards to cPanel itself. This would be like posting development questions in the Developer Discussions area that were general coding questions for PHP or Perl when they aren't related to cPanel. The intended focus of this forum is cPanel-based questions.

    General MySQL queries are a MySQL subject and best posted on the MySQL site itself if you cannot find out the information from an online search. The reason we'd suggest using that path is that most people on this forum will not know the information to answer the question.
     
  5. Huusoku

    Huusoku Active Member

    Joined:
    Dec 24, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Understood. Thanks for the clarification!

    -Huusoku
     
Loading...

Share This Page