SELECT td_stugor.ID
FROM td_stugor join td_stugor_faciliteter on td_stugor.ID=td_stugor_faciliteter.stugorID
where td_stugor_faciliteter.faciliteterID in (17,18)
group by td_stugor.ID
having count(*) = 2
Frågan#1
Databas: MySQL 4.0.24
Tabeller:
td_stugor med ID
td_faciliteter med ID
td_stugor_faciliteter med stugID och facilitetID
Tabellen td_stugor_faciliteter berättar vilka faciliteter som finns i varje stuga.
Ex:
stugID - facilitetID
53 - 17
53 - 18
Jag vill hämta alla stugor som har vissa faciliteter. Dvs. alla ID från td_stugor (ej stugID från td_stugor_faciliteter p.g.a. resten av SQL-satsen) som har facilitetID=17 och facilitetID=18
Följande fungerar ju inte:
SELECT td_stugor.ID FROM td_stugor, td_stugor_faciliteter WHERE td_stugor.ID=td_stugor_faciliteter.stugorID AND td_stugor_faciliteter.faciliteterID=17 AND td_stugor_faciliteter.faciliteterID=18
Tack på förhand
/Christer