Ordering by multiple columns in mysql with subquery
- by Scarface
Hey guys I have a query that selects data and organizes but not in the correct order. What I want to do is select all the comments for a user in that week and sort it by each topic, then sort the cluster by the latest timestamp of each comment in their respective cluster. My current query selects the right data, but in seemingly random order. Does anyone have any ideas?
select * from (
SELECT
topic.topic_title, topic.topic_id
FROM comments
JOIN topic ON topic.topic_id=comments.topic_id
WHERE comments.user='$user' AND comments.timestamp>$week order by comments.timestamp desc) derived_table
group by topic_id