Pabuc,
为了您最初的问题,使用何不让所有的结果针对给定问题/答复的单个查询?
select reply_text, user_id
from REPLIES
order by DATE asc
另外,正如您所指出的那样,除了微小的差异之外,问题和答案与帖子的属性几乎相同。
难道像下面的模型更有意义吗?问题和答案都是“帖子”,唯一的区别是答案的问题是父母,问题没有父母。
Create table post -- question/reply (
post_id number,
parent_post_id number, -- will be null if it is the question, will have the question id
-- if it is a reply to a question
post_text varchar2(4000),
user_id number,
post_date date);
-self referential foreign key
Alter table post
add constraint foreign key (parent_post_id) references post(post_id);
- 对所有帖子的评论(问题/回复)。
create table comments(
comment_id number,
post_id number,
comment_txt varchar2(140),
comment_user_id number,
comment_date date
);
alter table comments add constraint fk_comments_post
foreign key (post_id) references post(post_id).
- 对于一个给定的问题(后)的ID,你可以得到所有的答复和岗位使用...
select replies.*,
comments.*
from posts replies,
comments
where replies.parent_id = :Question_id --input
and comments.post_id = replies.post_id
您可能必须通过子句添加以获得满意的结果基于点,updated_timestamp或任何其他属性根据需要。
从SO可能是不同的主题,但你知道有StackExchange家族的许多主题网站?只是确保你知道,然后你对大狗; – 2011-02-28 19:16:14