Skip to content

Instantly share code, notes, and snippets.

@laribee
Created February 11, 2013 20:10
Show Gist options
  • Select an option

  • Save laribee/4757189 to your computer and use it in GitHub Desktop.

Select an option

Save laribee/4757189 to your computer and use it in GitHub Desktop.
SELECT TOP (100) PERCENT dbo.Forum.ID AS ForumID
, I.ID AS IdeaID
, (SELECT COUNT(*) FROM dbo.Vote WHERE (Idea_id = I.ID)) AS VoteCount
, (SELECT COUNT(*) FROM dbo.Comment WHERE (Idea_id = I.ID)) AS CommentCount
FROM dbo.Idea AS I
INNER JOIN dbo.Category ON I.Category_id = dbo.Category.ID
INNER JOIN dbo.Forum ON dbo.Category.Forum_id = dbo.Forum.ID
GROUP BY I.ID, dbo.Forum.ID
ORDER BY ForumID, IdeaID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment