---
title: "Ännu ett problem"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/21642-ännu-ett-problem"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "Andy"
published: "2001-10-02T13:35:00.000Z"
updated: "2001-10-02T14:48:00.000Z"
replies: 2
views: 157
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/databaser-sql/21642-ännu-ett-problem"
---

# Ännu ett problem

## #1 — Andy, 2001-10-02T13:35Z

Jag håller på och bygger ett forum och har följande tabeller liggande i en SQL 2000-databas:

tableForums
ID &#0124; Name

tableTopics
ID &#0124; BelongsInForum &#0124; Title

tablePosts
ID &#0124; BelongsToTopic &#0124; 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?

Permalänk: https://www.webforum.nu/p/21642

## #2 — LarsG, 2001-10-02T13:53Z

```
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
```

Permalänk: https://www.webforum.nu/p/352700

## #3 — Andy, 2001-10-02T14:48Z

Tack än en gång! Vad skulle jag göra utan dig? :)

Permalänk: https://www.webforum.nu/p/352701

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/21642-ännu-ett-problem
