我有兩個表,就像這樣:SQL查詢來獲取一個排,和相關的行數
#Articles:
ID | Title
1 "Article title"
2 "2nd article title"
#Comments:
ID | ParentID | Comment
1 1 "This is my comment"
2 1 "This is my other comment"
我一直想知道,什麼是最優雅的方式來得到以下結果:
ID | Title | NumComments
1 "Article title" 2
2 "2nd article title" 0
這是針對SQL Server的。
+1 ...我的想法也是;你太快了,喬爾。 – Adrien 2009-06-10 21:00:29
dang it you beat it me it to it ... + 1 – CodeLikeBeaker 2009-06-10 21:00:56
那麼,首先用正確的答案獲得積分!謝謝喬爾! – 2009-06-10 21:02:03