I have a table with the following fields:
p1
p2
s1
s2
where p1 -> player1, p2 -> player2, s1 -> game1, s2 -> game2 The no of players can vary from 3 - 10. The table have the results between them. Let's suppose that we have 4 players: TIM, ROB, NICK, GEORGE and his matches:
p1 p2 s1 s2
TIM ROB 4 0
NICK GEORGE 4 0
TIM NICK 0 4
ROB GEORGE 4 0
TIM GEORGE 4 0
ROB NICK 4 0
What I want to produce with the query is something like this:
TIM ROB NICK GEORGE
TIM X 4-0 0-4 4-0
ROB 0-4 X 4-0 4-0
NICK 0-4 4-0 X 4-0
GEORGE 0-4 0-4 0-4 X
Is it possible to have the above?
Till now the only thing I have achieved is to have it using GROUP_CONCAT combined with CONCAT using the following query:
SELECT RT.Player1, GROUP_CONCAT(CONCAT(RT.Player2,':',RT.Result1,'-', RT.Result2) SEPARATOR '\n'))
FROM
(SELECT R.p1 AS Player1, R.p2 AS Player2, R.s1 AS Result1, R.s2 AS Result2 FROM fab_matches AS R
UNION ALL
SELECT R.p2 AS Player1, R.p1 AS Player2, R.s2 AS Result1, R.s1 AS Result2 FROM fab_matches AS R) AS RT
However this is not the expected presentation...
Thanks in advance.