---
title: "join två tabeller med relationstabell"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/133450-join-två-tabeller-med-relationstabell"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "tlee"
published: "2005-08-29T14:51:27.000Z"
updated: "2005-08-29T18:29:31.000Z"
replies: 5
views: 372
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/133450-join-två-tabeller-med-relationstabell"
---

# join två tabeller med relationstabell

## #1 — tlee, 2005-08-29T14:51Z

okej..

tblUser: (tabell med info om användaren)
fldUserId
fldUseName

tblCat: (tabell med de olika kategorierna)
fldCatId
fldCatName
fldCatActive = on/off

tblUserCat: ("relationstabell" som innehåller vilka kateogirer som användaren har valt som aktiv)
fldUserId
fldCatId
fldActive = on/off

hur ser en sql ut som plockar en lista på vilka kategorier som är vald som aktiv av användaren?

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

## #2 — LarsG, 2005-08-29T15:03Z

```
select fldUserName,fldCatName
from tblUser u, tblCat c, tblUserCat uc
where u.fldUserId = uc.fldUserId
and uc.active = 'Yes'
and uc.fldCatId = c.fldCatId
```

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

## #3 — tlee, 2005-08-29T18:01Z

Microsoft OLE DB Provider for ODBC Drivers error '80004005' 

\[Microsoft\]\[ODBC Microsoft Access Driver\] The specified field 'fldUserId' could refer to more than one table listed in the FROM clause of your SQL statement. 

```
select fldCompany, fldUserId
from tblUser u, tblCat c, tblUserCat uc
where u.fldUserId = uc.fldUserId 
and uc.fldActive = 'on' 
and uc.fldCatId = c.fldCatId;
```

hmm?

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

## #4 — @nders, 2005-08-29T18:09Z

I SELECT-delen, specificera vilken tabell du vill hämta fältet ifrån, precis som du gjort i resten av frågan.

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

## #5 — tlee, 2005-08-29T18:24Z

ok.. nu får jag ett annat fel.. :)

select tblUser.fldCompany, tblUser.fldUserId from tblUser u, tblCat c, tblUserCat uc where u.fldUserId = uc.fldUserId and uc.fldActive = 'on' and uc.fldCatId = c.fldCatId; 

Microsoft OLE DB Provider for ODBC Drivers error '80040e10' 

\[Microsoft\]\[ODBC Microsoft Access Driver\] Too few parameters. Expected 2. 

/t/default.asp, line 79

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

## #6 — Peter S, 2005-08-29T18:29Z

```
select u.fldCompany, u.fldUserId
from tblUser u, tblCat c, tblUserCat uc
where u.fldUserId = uc.fldUserId 
and uc.fldActive = on 
and uc.fldCatId = c.fldCatId;
```

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

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/133450-join-två-tabeller-med-relationstabell
