我有两个表“member_registration”和“mebership_details”使用外键从两个表中获取行值,然后移动到另一个表“existing_members”,原始行值将被删除。
$query=mysql_query("existing_member(member_id,member_name,dob,gender,address,city,state,phone,email,height,weight,bmi,bp,medical,image_path,joining_date,)
SELECT member_id,member_name,dob,gender,address,city,state,phone,email,height,weight,bmi,bp,medical,image_path,joining_date FROM member_registration
WHERE member_id='".$memberid."'");
$query2=mysql_query("INSERT INTO existing_member (member_type) SELECT membership_type FROM membership_details
WHERE member_id='".$memberid."'");
if($query and $query2)
{ //echo "connected";
$sql=mysql_query("DELETE FROM member_registration WHERE member_id='".$memberid."'");
$sql1=mysql_query("delete from membership_details where member_id='".$memberid."'");
echo "<script>
alert('Data Deleted Successfully');
window.location.href='close_member.php';
</script>";
}
这是我的查询,单个查询,但如何执行两个查询以将两个表中的值插入到单个表中,
最佳答案
你可以尝试联合
下面的例子
insert into table1(col1, col2, col3) (
select col1 as col1, col2 as col2, col3 as col3 from table2
union
select col1 as col1, col2 as col2, col3 as col3 from table3)
小心 id(主键或唯一键),它可能已经存在,或者您可以使用插入忽略
希望这会有所帮助
关于php - 我想将两个不同的表行值插入到单个表中,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27616986/