So, I have one table, Threads
ThreadNumber | Sticky | Title
1 | 1 | Read This Before Posting!
2 | 0 | Second Topic
3 | 0 | Check This
And a second table, Posts
ThreadNumber | Author | Timestamp | Body | PostNumber
1 | User1 | 1 | Read up! | 0
1 | User2 | 2 | I see. | 1
2 | User2 | 3 | So tell me what'chu want! | 0
3 | User3 | 5 | Yeah, check this out. | 0
2 | User3 | 7 | What'chu really really want!| 1
2 | User1 | 10 | I'll tell you what I want! | 2
(Timestamp in Posts is the ten-digit second integer representation of time that the PHP time()
function gives out when the given user submits their comment to the db.) So, when it comes to showing all forum thread topics on the forum overview page, what I would like to do is present all of the threads in order of when their last comment was posted. I have tried my own hand at nested MySQL queries (didn't work out), so I started trying to do some research. Nothing else that I found was able to get me what I was looking for either. I feel like this came close, but I still got all the results given by unique ThreadNumbers. Ideally, what I would get returned is something like:
ThreadNumber | Title | LastTimestamp
2 | Second Topic | 10
3 | Check This | 5
1 | Read This Before Posting! | 1
Thanks a ton for reading this and any possible [and much needed] help!
I have tried
SELECT PostNumber, ThreadNumber, Body, Author, Timestamp
FROM (SELECT PostNumber, ThreadNumber, Body, Author, Timestamp
FROM Posts
ORDER BY Timestamp DESC) AS p
GROUP BY ThreadNumber;
which not only wouldn't have returned what I actually wanted, but didn't work the way I intended anyways.