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 need help with a query to get data and a count of related records.. I have two related tables.. Blog_Messages AS m & Blog_Comments AS cFor each record in m I want toSELECT * FROM m & SELECT Count From c WHERE m.messageID = c.messageIDdisplay like this.. My Blog1, title, message, date -Comments 3My Blog2, title, message, date -Comments 1ETC..
TG
Master Smack Fu Yak Hacker
6065 Posts
Posted - 2009-04-13 : 13:36:33
Is this what you're looking for?
select m.[My Blog1] ,m.[title] ,m.[message] ,m.[date] ,count(*) as Commentsfrom Blog_Messages AS m inner join Blog_Comments AS c on c.messageid = m.messageidgroup by m.[My Blog1] ,m.[title] ,m.[message] ,m.[date]