Table update problems

Source: Internet
Author: User
Table update problem! Both tables contain the serial number and device type fields. I want to update the device type value in table 2 to the device type value with the same serial number in Table 1 ?, $ SQL = & #39; SELECT * FROM Table 2 & #39; $ res = mysql_query ($ SQL) ordie table update problem!
Both tables contain the serial number and device type fields.
I want to update the device type value in table 2 as the device type value with the same serial number in Table 1. how can I write it?

------ Solution --------------------
$ SQL = 'select * FROM table 2 ';
$ Res = mysql_query ($ SQL) or die ('query failed: '. mysql_error ());
While ($ row = mysql_fetch_array ($ res )){
$ Sql1 = "SELECT * FROM Table 1 where serial number = $ row ['serial number '] limit 1 ";
$ Res1 = mysql_query ($ sql1) or die ('query failed: '. mysql_error ());
While ($ row1 = mysql_fetch_array ($ res )){
$ Sql2 = "update table 2 set device type value = $ row1 ['device type value'] where serial number = $ row ['serial number ']";
Mysql_query ($ sql2 );
}
}
---------------
This is probably the meaning. Change it by yourself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.