AndyMedlem sedan sep. 2001138 inlägg
Jag håller på och bygger ett forum och har följande tabeller liggande i en SQL 2000-databas:
tableForums
ID | Name
tableTopics
ID | BelongsInForum | Title
tablePosts
ID | BelongsToTopic | Title
Mellan tableForums.ID och tableTopics.BelongsInForum finns det en relation, vilket det även gör mellan tableTopics.ID och tablePosts.BelongsToTopic
På forumets förstasida vill jag visa forumets titel, antal topics, samt antal posts.
Hur gör men det på ett bra sätt?
LarsGMedlem sedan dec. 200012 465 inlägg
select name,(select count(*)
from tableTopics where
belongsInForum = tf.id) as numberOfTopics,
(select count(*) from tablePosts
where BelongsTopic in (
select id from tableTopics
where BelongsInForum = tf.id)) as numberOfPosts
from tableForums tf
------------------
essentitia preter non sans multiplicandum
[Redigerat av LarsG den 02 okt 2001]
AndyMedlem sedan sep. 2001138 inlägg
Tack än en gång! Vad skulle jag göra utan dig? :)