简体   繁体   English

如何从两个表中插入一个表中的值等于另一个表中的值的值?

[英]how to insert values from two tables with value in one table is equal to value in the other?

here i have two tables pro_zone_m and temp_const and i am inserting values into third table pro_m where i will be inserting zone from temp_const, and i need to get value of zone_id of corresponding zone from pro_zone_m. 在这里,我有两个表pro_zone_m和temp_const,我正在将值插入到第三表pro_m中,其中我将从temp_const插入zone,并且我需要从pro_zone_m获取相应区域的zone_id值。 i tried but could'nt able to come up with solution. 我尝试过,但无法提出解决方案。

$uisq = "SELECT * FROM pro_zone_m";
$ytu = mysql_query($uisq);
$mnm = mysql_fetch_array($ytu);
extract($mnm);


$wqr = "SELECT * FROM temp_const";
$wqe = mysql_query($wqr);
while($wqe1 = mysql_fetch_array($wqe))
{
extract($wqe1);


$zxc = "INSERT INTO pro_m set custid='$custid', firstname='$firstname',     lastname='$lastname', country='$country', 
city='$city', state='$state', zone='$zone', adresstype='$address_type',     address1='$address1', address2='$address2',category='$category', 
focus='$focus', assignto='$assign_to', division='$division',     product='$product', grade='$grade', potential='$potential',     designtn='$designation',
mobile='$mobile', primphone='$primary_phone', primemail='$primary_email',
exhibition = '$exhibition',  zonea_id = '$zoneid' WHERE zone = '$code' ";

$zxc1 = mysql_query($zxc);

Update your insert query like this:(assuming zonea_id will store zone_id from temp_const table. 像这样更新您的插入查询:(假设zonea_id将存储temp_const表中的zone_id。

$zxc = "INSERT INTO pro_m set custid='$custid', firstname='$firstname', lastname='$lastname', country='$country', city='$city', state='$state', zone='$zone', adresstype='$address_type', address1='$address1', address2='$address2',category='$category', focus='$focus', assignto='$assign_to', division='$division', product='$product', grade='$grade', potential='$potential', designtn='$designation', mobile='$mobile', primphone='$primary_phone', primemail='$primary_email', exhibition = '$exhibition', zonea_id = (SELECT zone_id FROM temp_const where zone = '$code') "; $ zxc =“ INSERT INTO pro_m set custid ='$ custid',firstname ='$ firstname',lastname ='$ lastname',country ='$ country',city ='$ city',state ='$ state', zone ='$ zone',adresstype ='$ address_type',address1 ='$ address1',address2 ='$ address2',category ='$ category',focus ='$ focus',Assignto ='$ assign_to',除法='$ division',产品='$ product',等级='$ grade',潜力='$ potential',designtn ='$ designation',mobile ='$ mobile',primphone ='$ primary_phone',primemail = ''$ primary_email',展览='$ exhibition', zonea_id =(从temp_const中选择zone_id,其中zone ='$ code') ”;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何插入两个表; 一个将插入 1 行,另一个将插入多行,两个表的一列具有相同的值 - how to insert into two tables; one will insert 1 row and the other one will insert multiple rows, the two tables has one column with the same value 从一个表中获取值,然后将其插入另一个表中。 如何? - Get value from one table, insert it in query of other. How to? 如果另一个表中的值相等,则更新一个表 - Update one table if value is equal in other table MySQL的两个表,从一个表中选择所有值,比较是否存在,然后返回一个随机值 - Mysql two tables, select all values from one table, compare if exists and then return One random value 尝试通过使用另一个表中的id值将两个表连接在一起 - Trying to connect two tables together by using id value from one table on the other 如何连接两个表,然后显示从另一个表收集的表的每个数据的总和值 - How to join two tables and then display the sum value of each data of a table gathering from the other table 如何将值从数据库中的所有表插入一个表 - How to Insert values into one table from all tables from database 如何在MySQL中将默认值从一个表插入到另一个表 - How to insert default values from one table to other in mysql 如何从SQL的同一表中的其他两个值创建值? - How can I create a value from two other values in the same table in my SQL? 如果一个表列为空,如何从另一表获取值 - How to get the value from the other table if one table column is empty
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM