1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple MySQL query searched

Discussion in 'General Programming Chat' started by subster, Feb 22, 2013.

  1. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Hi there,

    there must be a simple query to run that changes field B to 1 if field A = 1.
    I guess it something with a WHERE clause, but I am not really knowledged in MySQL.


    Basically I want to do the following:

    in table product_attributes where options_values_id = 1 change sortorder to 1 (value of the field)

    Thanks for your help!
     
  2. Xp3r7

    Xp3r7 Regular Member

    Joined:
    Sep 9, 2011
    Messages:
    286
    Likes Received:
    386
    Occupation:
    Freelancer
    Location:
    In the middle of nowhere
    Code:
    UPDATE product_attributes SET fieldB=1 WHERE fieldA=1
    
     
    • Thanks Thanks x 1
  3. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Thanks & Rep for quick help!
     
  4. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Oh, may I ask another query- This is a bit more difficult (and the las t I will ask for):

    In table ABC: If field A1 = 2 ADD 'text123' at the beginning of the values inside field B1

    Example:

    Field B1 before query: blablabla
    Field B1 after the query if A1 =2: text123 blablabla

    Perhaps I am lucky enough again to gain your help
     
  5. aying

    aying Junior Member

    Joined:
    Nov 8, 2011
    Messages:
    144
    Likes Received:
    27
    Code:
    UPDATE ABC SET B1 = 'text123 ' + B1 WHERE A1=2
     
    • Thanks Thanks x 1
  6. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Hm - Thank you for your help.
    phpMyAdmin does the query successfully, but unfortunately I have now only 0 in all that fields (B1 where A1=2)
     
  7. madoctopus

    madoctopus Supreme Member

    Joined:
    Apr 4, 2010
    Messages:
    1,249
    Likes Received:
    3,498
    Occupation:
    Full time IM
    • Thanks Thanks x 1
  8. aying

    aying Junior Member

    Joined:
    Nov 8, 2011
    Messages:
    144
    Likes Received:
    27
    Hmmm, what platform are you using? im assuming that you;re using mssql that's why i suggest to use "+", but it will depend on what platform you're using..maybe, try madoctopus suggestion :)

    The query is correct, but concatination will depend on what platform you're using..
     
    • Thanks Thanks x 1
  9. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    MO: that did it perfectly!

    I am afraid i have the next question i cant answer mysql through the docs...

    everything plays in the same table: wipe the value of field B, and copy the value of field A into B after that.

    aying, thought so. But am using mysql. I am sorry if I did not mention this. repped both of you for willingness to help. Thanks again!
     
    Last edited: Feb 23, 2013
  10. madoctopus

    madoctopus Supreme Member

    Joined:
    Apr 4, 2010
    Messages:
    1,249
    Likes Received:
    3,498
    Occupation:
    Full time IM
    Code:
    UPDATE ABC SET B = A 
    You dont whipe and then copy A to B. You just override B with what's in A. No need for 2 steps.

    And add WHERE clause if you need to apply just on some records. This is all basic SQL man you should learn SQL. I don't mind helping people but this is so basic that i'm thinking you just too lazy to learn basic SQL.
     
    • Thanks Thanks x 1
  11. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    yeah, you are right. I am asking for help as this is a field which i do need just in very few cases like this. one task to fullfill and then months nothing. so motivation to learn the basics is low to be honest.
    I hope you dont take it as a bad habit. For example if you guess one title tag in your on page seo leads in a performance loss of the page, you just ask for an optimization of this 125 chars and dont do the whole on page course. please correct me if you think my point of view is wrong. i just know my talents abd i will never be a talented database manager or coder as i am just to untidy for that.