Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- `t`.`id`,
- `t`.`title`,
- `t`.`date` as theme_date,
- `u`.`id` as user_id,
- `u`.`username` as user_username,
- COUNT(p.id) as count_posts,
- SUBSTRING_INDEX(GROUP_CONCAT(`p`.`id` ORDER BY `p`.`id` DESC SEPARATOR "| " ), "| ", 1) as last_post_id,
- SUBSTRING_INDEX(GROUP_CONCAT(`p`.`date` ORDER BY `p`.`id` DESC SEPARATOR "| " ), "| ", 1) as last_post_date,
- IFNULL(MAX(p.date), t.date) AS pts
- FROM
- `topics` t
- LEFT JOIN
- `posts` p ON `p`.`topics_id` = `t`.`id`
- LEFT JOIN
- `users` u ON `u`.`id` = `t`.`user_id`
- GROUP BY
- `t`.`id`
- ORDER BY
- `pts` DESC
- LIMIT 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement