So, I have a table spiller
with players and their id.
id | navn
-------------
1 | John Doe
2 | Matoma
3 | Lemaitre
4 | Koan
Secondly i have a table spillerpar
that puts players in pairs. This table consist of an Auto inc id and the foreign key of spiller
id x 2.
id | spiller_id_fk_1 | spiller_id_fk_2
--------------------------------------
1 | 1 | 4
2 | 3 | 2
Im trying to display the values of 2 fk's along with the fk id. I cant figure out how to. Please help.
select a.sid1, a.spiller1, b.sid2, spiller2
FROM
(Select 1_spillerpar.spiller_id_fk_1 as sid1, 1_spiller.navn as spiller1
From 1_spillerpar
Join 1_spiller
ON 1_spillerpar.spiller_id_fk_1 = 1_spiller.id) as a,
(Select 1_spillerpar.spiller_id_fk_2 as sid2, 1_spiller.navn as spiller2
From 1_spillerpar
Join 1_spiller
ON 1_spillerpar.spiller_id_fk_2 = 1_spiller.id) as b
EDIT
Desired output would look like:
id | spiller_id_fk_1 | navn | spiller_id_fk_2 | navn
--------------------------------------------------------
1 | 1 | John Doe| 4 | Koan
2 | 3 | Lemaitre| 2 | Matoma