mysql 连接两个表为一个表 两个表中有两个字段相同的要合并
把表结构交待下吧:t1:name,body+---------------------+----------+|name|desc|+------------------...
把表结构交待下吧:
t1 :name,body
+---------------------+----------+
| name | desc |
+---------------------+----------+
| STR_SWORD_CIRCULOUS | 性感泳装 |
| STR_GOBLIN_PICK | 游泳镜 |
+---------------------+----------+
t2 :id,desc
+-----------+---------------------+
| id | desc |
+-----------+---------------------+
| 100000001 | STR_SWORD_CIRCULOUS |
| 100000002 | STR_GOBLIN_PICK |
+-----------+---------------------+
现在问题是:name 和 desc 的值其实是相同的!
我希望得到的新表为这样的:
t3 :id,desc,name
+-----------+---------------------+---------+
| id | desc | name |
+-----------+---------------------+---------+
| 100000001 | STR_SWORD_CIRCULOUS | 性感泳装|
| 100000002 | STR_GOBLIN_PICK | 游泳镜 |
+-----------+---------------------+---------+ 展开
t1 :name,body
+---------------------+----------+
| name | desc |
+---------------------+----------+
| STR_SWORD_CIRCULOUS | 性感泳装 |
| STR_GOBLIN_PICK | 游泳镜 |
+---------------------+----------+
t2 :id,desc
+-----------+---------------------+
| id | desc |
+-----------+---------------------+
| 100000001 | STR_SWORD_CIRCULOUS |
| 100000002 | STR_GOBLIN_PICK |
+-----------+---------------------+
现在问题是:name 和 desc 的值其实是相同的!
我希望得到的新表为这样的:
t3 :id,desc,name
+-----------+---------------------+---------+
| id | desc | name |
+-----------+---------------------+---------+
| 100000001 | STR_SWORD_CIRCULOUS | 性感泳装|
| 100000002 | STR_GOBLIN_PICK | 游泳镜 |
+-----------+---------------------+---------+ 展开
4个回答
展开全部
create table t3
select t2.id,t2.desc,t1.desc as name
from t2
,t1
where t1.id = t2.id
select t2.id,t2.desc,t1.desc as name
from t2
,t1
where t1.id = t2.id
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试试
insert into t3(id,desc,name) (select t2.id,t1.name,t1.desc where t2.desc=t1.name)
insert into t3(id,desc,name) (select t2.id,t1.name,t1.desc where t2.desc=t1.name)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-07-07
展开全部
楼上正解!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
fbfbfbfbnfbfbhdfff
追问
犯病了啊?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询