Help with command to update prices

Discussion in 'Databases' started by oskare100, Mar 13, 2008.

  1. #1
    Hello,
    I have one table with the name dummy. In that table there is two columns I want to use, test1 which contains product ID's and test4 which contains prices.

    Then I have another table with the name products. In that table there amonh other columns two columns, one column with the name products_id with the products ids and another with the name products_prices which is the column I need to update with the prices from the test4 column in the dummy database.

    So I want to select the prices and products ids from the dummy table and update the prices in the products table.

    The products ids are the same in both tables and so is the number of lines. The only thing that differs is the prices, in the column test4 in the table dummy the real prices are and in the products table in the products_prices colum the wrong prices are that I want to update.

    The reason for wanting to to that is that all prices in the table my webshop uses has changed to zero... And that is not good, I can't give away all products : )

    Thanks
    Oskar
     
    oskare100, Mar 13, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    I can write you a php program for you which will do this

    PM me if interested


    Regards

    Alex
     
    kmap, Mar 13, 2008 IP
  3. oskare100

    oskare100 Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I maybe should add that only the products with products_price = 0 in the products table needs to be updated.
     
    oskare100, Mar 13, 2008 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I know that I think that PHP is useless but why on earth would you write any form of "program" to execute a single SQL query?

    
    UPDATE Products INNER JOIN Dummy 
          ON Products.Products_ID = Dummy.Test1 
    SET Products.Products_Price = Dummy.Test4;
    
    Code (SQL):
    You may need to put `` around field names etc depending on which db you are using
     
    AstarothSolutions, Mar 13, 2008 IP
  5. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #5
    Hi

    I know you are there so that is why i did not wrote that sql

    Thanks buddy

    Regards

    Alex
     
    kmap, Mar 14, 2008 IP
  6. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I just like to prove to my developers that I can do a small amount of programming and not just a pretty face (aka project manager)
     
    AstarothSolutions, Mar 14, 2008 IP