alphacooler
Programmer
I think I shot myself in the foot by not normalizing my forum schema. Here is what my table for forum posts looks like:
messageID (unique, auto increment)
threadID
groupID (index)
userID
subject
body
date_added
first_post (yes or no)
So for a specific Group/Forum page, I am trying to get a list of all Threads (first posts...first_post='yes') and order by date of last message in that thread (MAX(date_added) as last_post). However, this won't work with a "WHERE first_post='yes'" condition because then MAX(date_added) yields the first post date.
Any ideas?
FULL QUERY:
SELECT messages.threadID, messages.subject, MIN(messages.date_added) as min_date, messages.date_added, MAX(messages.date_added) as last_message, COUNT(messages.messageID) as num_messages
FROM messages
WHERE messages.groupID = $groupID AND messages.first_post='yes'
GROUP BY messages.threadID
ORDER BY last_message DESC
messageID (unique, auto increment)
threadID
groupID (index)
userID
subject
body
date_added
first_post (yes or no)
So for a specific Group/Forum page, I am trying to get a list of all Threads (first posts...first_post='yes') and order by date of last message in that thread (MAX(date_added) as last_post). However, this won't work with a "WHERE first_post='yes'" condition because then MAX(date_added) yields the first post date.
Any ideas?
FULL QUERY:
SELECT messages.threadID, messages.subject, MIN(messages.date_added) as min_date, messages.date_added, MAX(messages.date_added) as last_message, COUNT(messages.messageID) as num_messages
FROM messages
WHERE messages.groupID = $groupID AND messages.first_post='yes'
GROUP BY messages.threadID
ORDER BY last_message DESC