Just to expand on my previous issue – I have two tables in my database and I’ll like to extract certain information. Tables below:
(player): player_id (primary), playerName
(match): match_id (primary), playerID1, playerID2, playerID3, scorer etc..
You provided me with the following code to obtain the names of the players:
SELECT p.Name
FROM `match` m
INNER JOIN `player` p
ON p.player_id IN (m.playerID1, m.playerID2, m.playerID3) //etc
Works beautifully thanks – there’s just two adjustments I’d like to make:
- I’d like to return the name of the scorer as well as the player names. Since m.scorer is an ID, how do I map it to the p.Name attribute if p.Name is already being mapped to m.playerID?
- The above query returns the names of all the players. I will soon be adding a search feature where you search for all matches for a certain player. Is there anyway of excluding that player from the results (seeing as we already know this player was in the match as he was searched for). So pretty much return all matches, and fellow players for a certain player, but exclude the actual searched player from the results. Sorry if this is unclear, let me know and I’ll expand on it.
Try something like the following (assuming field names). It will show you the name of the player, the matchId of the match it was and whether they scored in that match or not :).
See this SQLFiddle HERE