situatie

Tabel:wedstrijd
records->uit_id,thuis_id,datum,wedstrijdnr

In uit en thuis staan de id's van teams

tabel: teams
records->id,teamnaam,club_id

tabel: club
records->id,clubnaam


nu wil ik het volgende uitvoer:

wedstrijdnr naamteam thuis(clubnaam) - naamteam uit(clubnaam) datum

hoe kan ik dit in 1 sql query verwerken ?
Als ik me 't goed herinner heb ik 't volgende laatst een keer langs zien komen. Ik garandeer niet dat 't werkt aangezien ik 't zelf nooit gebruikt heb.

SELECT 
thuis.teamnaam AS thuis_team, 
uit.teamnaam AS uit_team, 
wedstrijd.wedstrijdnr, 
thuis_c.clubnaam AS thuis_club, 
uit_c.clubnaam AS uit_club

FROM 
teams AS thuis, 
teams AS uit, 
clubs AS thuis_c, 
clubs as uit_c, 
wedstrijd 

WHERE 
wedstrijd.uit_id = uit.id AND 
wedstrijd.thuis_id = thuis.id AND 
thuis.club_id = thuis_c.id AND 
uit.club_id = uit_c.id;

Reageren