I build a forum system and I have a problem with fetching the last post.
Here is the query:
SELECT
posts.date, posts.author AS pauthor, topics.*,
CASE
WHEN posts.date > topics.date THEN posts.date
WHEN topics.date > posts.date THEN topics.date
END AS ldate
FROM
posts, topics
WHERE
topics.id = posts.topic_id
AND forum_id = ?
ORDER BY
ldate DESC
LIMIT 1
The problem is when I open a new topic is not appear unless I post a comment on this topic.