Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. SELECT
  2. `t`.`id`,
  3. `t`.`title`,
  4. `t`.`date` as theme_date,
  5. `u`.`id` as user_id,
  6. `u`.`username` as user_username,
  7. COUNT(p.id) as count_posts,
  8. SUBSTRING_INDEX(GROUP_CONCAT(`p`.`id` ORDER BY `p`.`id` DESC SEPARATOR "| " ), "| ", 1) as last_post_id,
  9. SUBSTRING_INDEX(GROUP_CONCAT(`p`.`date` ORDER BY `p`.`id` DESC SEPARATOR "| " ), "| ", 1) as last_post_date,
  10. IFNULL(MAX(p.date), t.date) AS pts
  11. FROM
  12. `topics` t
  13. LEFT JOIN
  14. `posts` p ON `p`.`topics_id` = `t`.`id`
  15. LEFT JOIN
  16. `users` u ON `u`.`id` = `t`.`user_id`
  17. GROUP BY
  18. `t`.`id`
  19. ORDER BY
  20. `pts` DESC
  21. LIMIT 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement