Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- c.id,
- c.CategoryName,
- c.Description,
- (SELECT count(t.id)
- FROM topic t
- WHERE t.categoryId = c.id) AS NumberOfTopics,
- (SELECT count(p.id)
- FROM post p
- JOIN topic t ON p.topicId = t.id
- WHERE t.categoryId = c.id) AS NumberOfPosts,
- (SELECT top 1 max(p.createdOn)
- FROM post p
- JOIN topic t ON p.topicId = t.id
- WHERE t.categoryId = c.id) AS LastPostDate,
- (SELECT top 1 createdby
- FROM post p
- JOIN topic t ON p.topicId = t.id
- WHERE t.categoryId = c.id
- ORDER BY p.createdon DESC) AS byperson
- FROM
- category c;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement