I have two tables.
“threads” with the columns ID, forumID, title, content, unixtime
“comments” with the columns ID, threadID, content, unixtime
I would like to do a mysql query which sorts all the rows within these two tables based on their unixtime, but also not showing the same “threadID” twice.
The following query will merge the two tables and sort them, but I cant remove duplicates of the threads. I’ve tried with some GROUP BY and DISTINCT, but with no luck.
(SELECT unixtime, ID, threadID FROM comments)
UNION
(SELECT unixtime, ID, forumID FROM threads)
ORDER BY unixtime DESC
Its for showing of the frontpage of a forum, therefor it would make no sense to let the same thread appear more than once.
EDIT: I want to show both the newest comments and the newest threads.
I changed some stuff. I asume you want to know if it’s a forum or thread id?