Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Designing a forum: Ordering my topics

Status
Not open for further replies.

Scorez2000

Programmer
Feb 5, 2004
87
GB
Hi,

I've started developing my new discussion board, nut I am having trouble ordering the list of topics.

It's all very simple so far. I have 3 tables (users, threads and replies).

The thread table contains the title of the thread, the contents of the first post and the date and time of the post.

Then the replies table has all the replies to that thread.

Here is a screenshot of my query so far:
The thing is, if I order by the date and time in the thread table, then threads will not 'bump' to the top when someone posts in them.

I cannot sort by the field in the replies folder either as it will have some blank fields in the records that are actually the first post.

Does anyone know how to create a query that will output the username and name of the thread, and order them by the date of the last reply in each thread?

Thanks in advance,

Wayne.
 
Ok, that's working kind of well, but I need it to sort on two fields each time.

So if it's null it sorts by thread.postDate and thread.PostTime

if it's not null, it sorts by replies.postdate and replies.posttime
 
Infact, that isn't working at all. It doesn't seem to be in any particular order.
 
This seems to do the trick:

SELECT User.Username, Thread.ThreadTitle, Max(IIf(IsNull([ReplyDateTime]),[Thread].[PostDateTime],[Replies].[ReplyDateTime])) AS Expr1
FROM [User] INNER JOIN (Replies RIGHT JOIN Thread ON Replies.ThreadID = Thread.ThreadID) ON User.UserID = Thread.AuthorID
GROUP BY User.Username, Thread.ThreadTitle
ORDER BY Max(IIf(IsNull([ReplyDateTime]),[Thread].[PostDateTime],[Replies].[ReplyDateTime])) DESC;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top