用SQL合并两张表放在一张新表中,该怎样?

zeng_pipi 2013-03-05 11:21:53
我的表Reply有Rid,Rcontents,Rtime,Cid,Rtime,Uid这些字段,Reverts有RRid,RRcontents,Rtime,Cid,Rtime,Uid,Rid这些字段。其中Rid和RRid分别是他们的ID值,我现在要把他们的Rcontents和RRcontents放在同一个属性contents中,两个Rtime放在time属性中,Cid放Cid中,Uid放Uidz中,这个怎么用SQL语句来实现呢?求解啊。。
...全文
7516 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
dd_zhouqian 2013-10-10
  • 打赏
  • 举报
回复
引用 5 楼 Ryan20082009 的回复:
用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union all select rrid as id,rcontents as contents,rrtime as time from reverts
楼主要这样?

select * from 
(select rid as id,rcontents as contents,rtime as time from reply
union all
select rrid as id,rcontents as contents,rrtime as time from reverts) as t 
generhappy 2013-10-10
  • 打赏
  • 举报
回复
union all
limi_tao 2013-10-10
  • 打赏
  • 举报
回复
建个视图不就好了
still_melody 2013-03-06
  • 打赏
  • 举报
回复
引用 3 楼 zeng_pipi 的回复:
引用 1 楼 still_melody 的回复:用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union select rrid as id,rcontents as contents,rrtime as time from……
已经用sql合并成新表里
zeng_pipi 2013-03-06
  • 打赏
  • 举报
回复
引用 1 楼 still_melody 的回复:
用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union select rrid as id,rcontents as contents,rrtime as time from reverts
不用放在一个新表中么?因为我要用数据绑定控件绑定这些字段。
qxyywy 2013-03-06
  • 打赏
  • 举报
回复
引用 1 楼 still_melody 的回复:
用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union select rrid as id,rcontents as contents,rrtime as time from reverts
已经给你写出来了
Ryan20082009 2013-03-06
  • 打赏
  • 举报
回复
用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union all select rrid as id,rcontents as contents,rrtime as time from reverts
zeng_pipi 2013-03-06
  • 打赏
  • 举报
回复
引用 8 楼 still_melody 的回复:
不明白你说的。 如果你是用adapter的话 adapter.Fill(mydataset) mydataset.datatable[0]就是你要找的表。直接绑定数据控件就行了
不好意思哈,我是说我绑定数据控件的时候还要把这个合成的新表和数据库中的其他表连接查询。。
ShenWong 2013-03-06
  • 打赏
  • 举报
回复
引用 9 楼 patric05034 的回复:
引用 7 楼 zeng_pipi 的回复:引用 5 楼 Ryan20082009 的回复:用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union all select rrid as id,rcontents as con……
+1 用 union all
Bule 2013-03-06
  • 打赏
  • 举报
回复
引用 7 楼 zeng_pipi 的回复:
引用 5 楼 Ryan20082009 的回复:用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union all select rrid as id,rcontents as contents,rrtime as time ……
select rid as id,rcontents as contents,rtime as time from reply union all select rrid as id,rcontents as contents,rrtime as time from reverts 把他当做一个sql,查询数据库,得到一个datatable,然后绑定到控件上就行了。不用给名字。
still_melody 2013-03-06
  • 打赏
  • 举报
回复
不明白你说的。 如果你是用adapter的话 adapter.Fill(mydataset) mydataset.datatable[0]就是你要找的表。直接绑定数据控件就行了
zeng_pipi 2013-03-06
  • 打赏
  • 举报
回复
引用 5 楼 Ryan20082009 的回复:
用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union all select rrid as id,rcontents as contents,rrtime as time from reverts
那给这个新表一个新的名字应该怎么写呢,就是把读到的数据放在一个表里面去。。。
zeng_pipi 2013-03-06
  • 打赏
  • 举报
回复
引用 4 楼 still_melody 的回复:
引用 3 楼 zeng_pipi 的回复: 引用 1 楼 still_melody 的回复:用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union select rrid as id,rcontents as contents,rrtime as……
因为这个新表我要和其他的表合起来进行查询,所以是不是要给这个表一个名字,我好方便查询。。。查询后我还要绑定在控件中显示出来的。。
still_melody 2013-03-05
  • 打赏
  • 举报
回复
用union 必须保证前后字段名称。数目。数据类型一致 select rid as id,rcontents as contents,rtime as time from reply union select rrid as id,rcontents as contents,rrtime as time from reverts

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧