你好,大家好,我有以下我的表關係子查詢,加入,而不是在SQL Server
和我寫在我的存儲過程
. Select useremail,fullname,city,[state], allowAlerts,allowLetters,aboutMe,avatar,dateregistered,
(Select COUNT(*) from blog_info where blog_info.userId = @userId)as blogCount,
(Select count(*) from blog_info where blog_info.isfeatured = 1 AND blog_info.userId = @userId)as featuredCount,
(Select COUNT(*) from blog_comments where blog_comments.userId = @userId)as commentsCount,
(Select COUNT(*) from forum where forum.createdby = @userId) as forumCount,
(Select COUNT(*) from forumresponse where forumresponse.userId = @userId)as responseCount
from user_info where _id = @userId.
以下嵌套查詢我想用連接的查詢替換這個嵌套的查詢。
請幫助我做到這一點。
由於提前
爲什麼你要轉換的加入? – Oded 2011-04-17 08:01:15
由於性能問題。由於與子查詢相比,聯接的性能更強。 – Abhi 2011-04-17 08:02:32
爲什麼你想用連接替換嵌套查詢?你希望獲得更高效的查詢嗎?我懷疑它會有幫助。加入用戶ID似乎並不適合這裏。 – Codo 2011-04-17 08:50:37