I have two tables, one with this form:
table teams:
ID, IDPupil1, IDPupil21 3000 3001
and the second this form:
table pupils:
ID, Name, Forename3000 Smith John3001 Morgan Lisa
IDPupil1 and IDPupil2 are referencing at pupils.ID.
Now I want to select all this values in one SQL-query.I tried this:
SELECT teams.ID AS ID, IDPupil1, IDPupil2, pupils.Name AS Name, pupils.Forename AS ForenameFROM teamsLEFT JOIN pupilsON IDPupil1 = pupils.IDAND IDPupils2 = pupils.ID
The result is this:
ID, IDPupil1, IDPupil2, Name, Forename1 3000 3001 NULL NULL
When I cancel the last row of the query (AND IDPupil2 = pupils.ID
), then the Name and Forename of Pupil1 is shown. But with both indexes it obviously doesn't work.
So how can I get the following result?
ID, IDPupil1, IDPupil2, Name1, Forename1, Name2, Forename21 3000 3001 Smith John Morgan Lisa