I have a table of players where I have all the data of the players, in this case the name and surname, then I have another table where I have match results, in that match results table I have two fields called player_a and player_b ( these two fields are part of the same record), these fields have the id that corresponds to the id of the players table. What I need is to know how I get the name and surname of the two players in the same query. I can only get the first and last name of one of the players but not both. I leave the query I made as an example.
SELECT nombre.jugadores, apellido.jugadores from jugadores INNER JOIN juegos ON jugadores.id = juegos.jugador_a WHERE id = 170
You would have to include the table twice
jugadores
in the query, once to relate it to the columnjugador_a
and once to relate it to thejugador_b
. Then the names would be obtained for each respective table (I have given the aliasesa
andb
tables for this case).The only doubt here is the
id
delWHERE
, I've assumed it refers to the columnid
of the tablejuegos
: