Hey guys, I am trying to implement my own forum, and I am stuck on how to do this efficiently. Here is the schema that I have in mind, but feel free to change it if it isnt possible to do what I want:
[Table: Threads]
int threadID
[Table: Posts]
int threadID
int postID
date datePosted
text postText
bool isThread
Using as few queries as possible, I would like to be able to retrieve all of the most recent posts as well as their original threads they posted in (which would be the post with the same threadID that has isThread set to true). I have been thinking of a solution that only takes 2 queries:
1) Retrieve all of the most recent posts that are unique in threadID
2) Retrieve all of the posts that have the same threadID as the resulting set from step 1, but have isThread = true.
My problem is I have no idea how to do this. I have been looking at select distinct, but it seems it can only retrieve one column. Any ideas? =D
[Table: Threads]
int threadID
[Table: Posts]
int threadID
int postID
date datePosted
text postText
bool isThread
Using as few queries as possible, I would like to be able to retrieve all of the most recent posts as well as their original threads they posted in (which would be the post with the same threadID that has isThread set to true). I have been thinking of a solution that only takes 2 queries:
1) Retrieve all of the most recent posts that are unique in threadID
2) Retrieve all of the posts that have the same threadID as the resulting set from step 1, but have isThread = true.
My problem is I have no idea how to do this. I have been looking at select distinct, but it seems it can only retrieve one column. Any ideas? =D