How can I update one table field to another table field?

Posted on 2007-10-08
Last Modified: 2013-12-13
I'm taking data from one table and updating another table.  

MySQL client version: 4.1.22

$query = "SELECT itemnum, description FROM item_test";
$results = mysql_query($query) or die(mysql_error());;

while($row = mysql_fetch_array ($results)) {
    $query = "UPDATE Items SET description = '{$row['description']}'
      WHERE itemnum = '{$row['itemnum']}'";
    mysql_close(); // Close the connection.
    print '<p>Successfully CLOSE connected to MySQL.</p>';

I'm going a little crazy...   It's only updating a few records?  

Could you please review it and see if I did something wrong?  
Question by:usiff

    Author Comment

    When I change the sql to this...

          $sql = "UPDATE Items SET description = '".$row['item_test.description']."' WHERE itemnum = '".$row['item_test.itemnum']."'";

    i'm getting this error

    Fatal error: Maximum execution time of 30 seconds exceeded in


    LVL 34

    Accepted Solution

    How about just using one sql?:

    update items inner join items_test on items.itemnum = items_test.itemnum
     set items.description = items_test.description

    Author Comment

    Hello TerryAtOpus,

    First of all it worked... Thanks...

    If you don't mind me asking...  
     Does inner join in this sql only look for unique records?  


    LVL 34

    Expert Comment

    by:Terry Woods
    It targets the rows from items where there exists a row in items_test with the same itemnum.

    If the itemnum wasn't unique in either of the tables, then you would probably get odd behaviour, so it's important that it's unique in both.

    Author Comment


    I have 10,000 records in both tables and it only updated 171.  Which is fine, because that's the only ones that I needed.    

    Thanks again...

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now