Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
i have Table_Posts(PostID, Title, Body) and Table_PostsReplies(PostID, ReplyPostID). i want to select the posts (postID, Title, Body, noReplies) starting with post @startIndex and finishing with @stopIndex.in ms sql i cannot use select count .. group by in a subselect.. also i cannot use top @variable only select top n.. please help how to select noPosts replies for each post and how to select posts from a range of indexes.i need help writing this complex query.
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-05-07 : 06:28:52
Is this what you want ? If not, post the table structure, some sample data and the expected result
select p.PostID, p.Title, p.Body, count(*) as noRepliesfrom Table_Posts p inner join Table_PostsReplies ron p.PostID = r.PostIDwhere p.PostID >= @startIndexand p.PostID <= @stopIndexgroup by p.PostID, p.Title, p.Body