用php把mysql的2个表合并生成新表?
数据库里有biaoa,biaob,想生成新的biaoc,麻烦给个具体点的代码!biaoaid1card1time1place11340056732019.1.221号楼2...
数据库里有biaoa,biaob,想生成新的biaoc,麻烦给个具体点的代码!
biaoa
id1 card1 time1 place1
1 34005673 2019.1.22 1号楼
2 34005673 2019.1.21 2号楼
biaob
id2 name2 number2 card2
1 张三 20190001 34005673
biaoc
id3 name3 number3 time3 place3
1 张三 20190001 2019.1.22 1号楼
2 张三 20190001 2019.1.21 2号楼 展开
biaoa
id1 card1 time1 place1
1 34005673 2019.1.22 1号楼
2 34005673 2019.1.21 2号楼
biaob
id2 name2 number2 card2
1 张三 20190001 34005673
biaoc
id3 name3 number3 time3 place3
1 张三 20190001 2019.1.22 1号楼
2 张三 20190001 2019.1.21 2号楼 展开
3个回答
展开全部
首先解决,查询数据
1
select userlist.userid,userlist.username,userinformation.address from userlist left join userinformation on userlist.userid=userinformation.userid
然后,再把查询数据,插入到新表即可
只要在上面的语句,加上插入这句sql就可以了,最终语句如下
1
insert into `user` select userlist.userid,userlist.username,userinformation.address from userlist left join userinformation on userlist.userid=userinformation.userid
1
select userlist.userid,userlist.username,userinformation.address from userlist left join userinformation on userlist.userid=userinformation.userid
然后,再把查询数据,插入到新表即可
只要在上面的语句,加上插入这句sql就可以了,最终语句如下
1
insert into `user` select userlist.userid,userlist.username,userinformation.address from userlist left join userinformation on userlist.userid=userinformation.userid
2019-01-23
展开全部
<?php
$host="域";-- $type="数据库类型";-- $dbname="数据库名";-- $name="用户名"; -- $pass="密码";
$dsn="$type:host=$host;dbname=$dbname";
$pdo=new PDO($dsn,$name,$pass);//连接数据库
$sql="select * from biaoa union select * from biaob ";
$res=pdo->query($sql);
?>
$host="域";-- $type="数据库类型";-- $dbname="数据库名";-- $name="用户名"; -- $pass="密码";
$dsn="$type:host=$host;dbname=$dbname";
$pdo=new PDO($dsn,$name,$pass);//连接数据库
$sql="select * from biaoa union select * from biaob ";
$res=pdo->query($sql);
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2019-01-23
展开全部
直接用mysql语句插入,也可以用php连接数据库后执行该mysql语句
INSERT INTO biaoc SELECT a.id1 AS id3, b.name2 AS name3, b.number2 AS number3, a.time1 AS time3, a.place1 AS place3 FROM biaoa AS a LEFT JOIN biaob AS b ON a.card1 = b.card2
INSERT INTO biaoc SELECT a.id1 AS id3, b.name2 AS name3, b.number2 AS number3, a.time1 AS time3, a.place1 AS place3 FROM biaoa AS a LEFT JOIN biaob AS b ON a.card1 = b.card2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |