I have a table with match identifiers and corresponding player/team identifiers expressed as home
/ away
.
Each team, tid
, consist of two players and each player has its own identifier, pid
.
The problem is that in table matches
I don’t know whether the column home
/ away
represents a team or a single player.
I would like to add the columns home_ids
for each match which represent the player identifiers of the home player/team. I wrote the following query that gives an “Result: row value misused”-error
SELECT match_id,
CASE WHEN (SELECT pid FROM players WHERE m.home = pid)
IS NULL THEN (SELECT pid_1, pid_2 FROM teams WHERE m.home = tid)
ELSE (m.home, NULL)
END AS home_ids
FROM matches m
How to modify my query so it works as intended?