SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question unique UPDATE using a JOIN?

    I need something rather unique...
    I have an older table with data like this:

    Table Name:
    table1

    Column names:

    PropertyID
    Field
    Amount

    The use of this was that the "Field" column had a set value like "price" and the "Amount" column had the price... say "1,000". The "PropertyID" is what matched up to a second table (lets call it table2) that had a matching "PropertyID" column.

    I am now trying to use just table2 and want to migrate the values from table1 to table2 all at once. I need to write an MySQL query or a PHP page that can grab the values from table1, and UPDATE table2 inserting the value of the column "Amount" in a new column called "Price" in table2, where table2.PropertyID=table1.PropertyID.

    I have tried a few things but I am missing something.
    Last edited by window2; Aug 5, 2005 at 19:51.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,274
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    UPDATE table2, table1 
       SET table2.price = table1.amount
     WHERE table2.PropertyID = table1.PropertyID;
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •