我用asp.net做论坛,数据库采用sql server 2000
把主贴和跟帖分别放入两张表里面
怎样将主贴和跟贴联合起来
主贴表
id 帖子编号
uid 用户编号
title 帖子标题
content 帖子内容
counts 帖子点击次数
endtimes 最后更新时间
跟帖表
id 编号
zid 主题编号(对应主贴表里的编号)
uid 回帖人编号
content 回帖内容
fbtimes 回帖时间
比如主贴表里有一个主题,跟帖表里有这个主题的两个跟帖,怎样将这两个表的内容联合起来,变成三条数据显示在页面上???
------解决方案--------------------------------------------------------
union
------解决方案--------------------------------------------------------
select ID,... from 主贴表 where 条件
union
select ID,... from 从表 where 条件
列要一致,就是类型和数量一致
------解决方案--------------------------------------------------------
- SQL code
select id,uid,content from 主贴表 where id=1union allselect zid,uid,content from 跟贴表 where zid=1
------解决方案--------------------------------------------------------
用联合语句查询.
------解决方案--------------------------------------------------------
联合语句