Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. SELECT
  2. c.id,
  3. c.CategoryName,
  4. c.Description,
  5. (SELECT count(t.id)
  6. FROM topic t
  7. WHERE t.categoryId = c.id) AS NumberOfTopics,
  8. (SELECT count(p.id)
  9. FROM post p
  10. JOIN topic t ON p.topicId = t.id
  11. WHERE t.categoryId = c.id) AS NumberOfPosts,
  12. (SELECT top 1 max(p.createdOn)
  13. FROM post p
  14. JOIN topic t ON p.topicId = t.id
  15. WHERE t.categoryId = c.id) AS LastPostDate,
  16. (SELECT top 1 createdby
  17. FROM post p
  18. JOIN topic t ON p.topicId = t.id
  19. WHERE t.categoryId = c.id
  20. ORDER BY p.createdon DESC) AS byperson
  21. FROM
  22. category c;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement