[SQL] record uit table1 waar in table2 2 rows van voorkomen

Pagina: 1
Acties:

  • Juup
  • Registratie: Februari 2000
  • Niet online
Ik heb een tabel "auto" met auto's en een tabel "optie" met opties. Voor 1 record in "auto" kunnen er meerdere records in "optie" zitten.

Nu wil ik alle records uit "auto" waarvoor in "optie" zowel optie "trekhaak" als optie "airco" voorkomt. Beide dus tegelijk.

Hoe moet dit (MySQL)?
Dit werkt niet (duh):
SQL:
1
2
3
4
5
SELECT *
FROM auto, optie
WHERE auto.id=optie.autoid
AND optie.text="trekhaak"
AND optie.text="airco"

Een wappie is iemand die gevallen is voor de (jarenlange) Russische desinformatiecampagnes.
Wantrouwen en confirmation bias doen de rest.


  • glashio
  • Registratie: Oktober 2001
  • Laatst online: 06-05 20:30

glashio

C64 > AMIGA > PC

code:
1
2
3
4
5
6
7
8
9
10
SELECT *.a
FROM auto a,optie o1,optie o2
WHERE
a.id=o1.autoid
AND
a.id=o2.autoid
AND
o1.text='trekhaak'
AND
o2.text='airco'
edit:
NP ;)

[ Voor 15% gewijzigd door glashio op 16-05-2005 15:41 ]

> Google Certified Searcher
> Make users so committed to Google that it would be painful to leave
> C64 Gospel
> [SjoQ] = SjoQing


  • Juup
  • Registratie: Februari 2000
  • Niet online
Ja dat is hem. Dank je wel.

Een wappie is iemand die gevallen is voor de (jarenlange) Russische desinformatiecampagnes.
Wantrouwen en confirmation bias doen de rest.