[SQL/Python] Writing SQL Statement for specific use-case
Go to solution
Solved by Zalosath,
A bit complex but I got it working:
SELECT p.* FROM posts p LEFT JOIN ( SELECT parent_post_id, MAX(timestamp) AS max_timestamp FROM posts WHERE parent_post_id IS NOT NULL GROUP BY parent_post_id ) p2 ON p.post_id = p2.parent_post_id WHERE p.parent_post_id IS NULL AND forum_id=1 ORDER BY p2.max_timestamp DESC

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now